# Captcha brauchen Ewigkeiten beim erstellen.

**URL:** <https://forum.shopware.com/t/captcha-brauchen-ewigkeiten-beim-erstellen/11919>\
**Category:** Shopware 3.5\
**Tags:** general\
**Created:** [2. März 2013 um 16:49 UTC](https://forum.shopware.com/t/captcha-brauchen-ewigkeiten-beim-erstellen/11919 "2013-03-02T16:49:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dexus](https://avatars.discourse-cdn.com/v4/letter/d/c68b51/32.png) [@Dexus](https://forum.shopware.com/u/Dexus)\
**Post date:** [2. März 2013 um 16:49 UTC](https://forum.shopware.com/t/captcha-brauchen-ewigkeiten-beim-erstellen/11919/1 "2013-03-02T16:49:09Z")

</div>

Hallo, ich habe heute einen Shop aufgesetzt, bei dem ich das Problem habe das die Captchas Ewigkeiten brauchen, bis diese Angezeigt werden. Bei den Vorgänger Versionen war das nie ein Problem aber mit der 4.0.6 laden die Capchas erst nach dem die maximale Script Laufzeit erreicht wurde. Ich verwende PHP 5.3.21, und NGINX als Webserver.

---

<div class="post-metadata">

**Author:** ![leseaw](https://avatars.discourse-cdn.com/v4/letter/l/73ab20/32.png) [@leseaw](https://forum.shopware.com/u/leseaw)\
**Post date:** [2. März 2013 um 17:21 UTC](https://forum.shopware.com/t/captcha-brauchen-ewigkeiten-beim-erstellen/11919/2 "2013-03-02T17:21:38Z")

</div>

ann ich bestätigen Apache2 mit APC und Nginx als Proxy selbe Spass ☹

---

<div class="post-metadata">

**Author:** ![Dexus](https://avatars.discourse-cdn.com/v4/letter/d/c68b51/32.png) [@Dexus](https://forum.shopware.com/u/Dexus)\
**Post date:** [3. März 2013 um 13:35 UTC](https://forum.shopware.com/t/captcha-brauchen-ewigkeiten-beim-erstellen/11919/3 "2013-03-03T13:35:30Z")

</div>

So habe es nun selber gelöst: [code]\<?php …  
/\*\*

- Shopware Captcha Controller
- 
- todo@all: Documentation  
_/  
class Shopware\_Controllers\_Widgets\_Captcha extends Enlight\_Controller\_Action  
{  
/_\*
  - Pre dispatch action method
  - 
  - Sets no render on some actions  
\*/  
public function preDispatch()  
{  
$this-\>Front()-\>Plugins()-\>ViewRenderer()-\>setNoRender(); } /\*\* \* Index action method \* \* Creates a captcha and then outputs it. \*/ public function indexAction() { $captcha = ‚frontend/\_resources/images/captcha/background.jpg‘; $font = ‚frontend/\_resources/images/captcha/font.ttf‘; $template\_dirs = Shopware()-\>Template()-\>getTemplateDir(); foreach ($template\_dirs as $template\_dir) { if (file\_exists($template\_dir . $captcha)) { $captcha = $template\_dir . $captcha; break; } } foreach ($template\_dirs as $template\_dir) { if (file\_exists($template\_dir . $font)) { $font = $template\_dir . $font; break; } } $random = $this-\>Request()-\>rand; $random = md5($random); $string = substr($random, 0, 5); if (file\_exists($captcha)) { $im = imagecreatefromjpeg($captcha); } else { $im = imagecreatetruecolor(162, 87); } if (!empty(Shopware()-\>Config()-\>CaptchaColor)) { $colors = explode(’,’, Shopware()-\>Config()-\>CaptchaColor); } else { $colors = explode(’,’, ‚255,0,0‘); } $black = ImageColorAllocate($im, $colors[0], $colors[1], $colors[2]); $string = implode(’ ', str\_split($string)); if (file\_exists($font)) { for ($i = 0; $i \<= strlen($string); $i++) { $rand1 = rand(35, 40); $rand2 = rand(15, 20); $rand3 = rand(60, 70); imagettftext($im, $rand1, $rand2, ($i + 1) \* 15, $rand3, $black, $font, substr($string, $i, 1)); imagettftext($im, $rand1, $rand2, (($i + 1) \* 15) + 2, $rand3 + 2, $black, $font, substr($string, $i, 1)); } for ($i = 0; $i \< 8; $i++) { imageline($im, mt\_rand(30, 70), mt\_rand(0, 50), mt\_rand(100, 150), mt\_rand(20, 100), $black); imageline($im, mt\_rand(30, 70), mt\_rand(0, 50), mt\_rand(100, 150), mt\_rand(20, 100), $black); } } else { $white = ImageColorAllocate($im, 255, 255, 255); imagestring($im, 5, 40, 35, $string, $white); imagestring($im, 3, 40, 70, ‚missing font‘, $white); } ob\_start(); imagejpeg($im, NULL, 90); imagedestroy($im); $i = ob\_get\_contents(); $this-\>Response()-\>setHeader(‚Content-Type‘, ‚image/jpeg‘, true); $this-\>Response()-\>setHeader(‚Content-Length‘, strlen($i)); echo $i; exit; // neu hinzugefügt, nun kein minutenlanges waren auf ein Captcha } }[/code]

---

<div class="post-metadata">

**Author:** ![leseaw](https://avatars.discourse-cdn.com/v4/letter/l/73ab20/32.png) [@leseaw](https://forum.shopware.com/u/leseaw)\
**Post date:** [3. März 2013 um 15:51 UTC](https://forum.shopware.com/t/captcha-brauchen-ewigkeiten-beim-erstellen/11919/4 "2013-03-03T15:51:39Z")

</div>

thx 🙂 und den Pfad noch bitte eintragen wo die Datei ist okay dann mach ich es : engine/Shopware/Controllers/Widgets/Captcha.php
