Fix: Using Magic 360 Crashes Apache on Windows 7 XAMPP environment

While in the process of using some of MagicToolbox’s awesome website tools for one of the sites I maintain, I ran into a stumper that cost me several hours of head banging.  I’m sharing it for my own sanity down the road and if I help you out in the process, well let’s just say that’s icing on the cake!

I downloaded and installed (according the the instructions) the Magic Zoom and Magic 360 Magento modules and to my amazement they seem to just work out of the box!  The team there really did an excellent job on crafting this toolset!  It wasn’t until I was testing out the Magic 360 that I discovered a set back.  (For the record, I’m running a XAMPP environment on a Windows 7 PC and am more-or-less a newbie on Magento and LAMP in general.)  I was loading the images for a given product and when I saved the product, the Apache server just crashed!  Time and again, after I clicked the Save or Save and Continue in Magento I would see the following:

image

Stepping through the code brought me to their saveProductImagesData function within the Observer.php file.  Within that function is a call to the database with an update statement:

$connection->query("UPDATE {$table} SET columns = {$columns}, gallery = '{$data}' WHERE product_id = {$id}");

From this point, the Zend DB library takes over and it is there that the Apache server crashes.  More specifically, the offending line of code is in the lib/Zend/Db/Statement.php file line 204:

$sql = preg_replace("/$q($qe|\\\\{2}|[^$q])*$q/", '', $sql);

As it turns out, there is a little known bug around the preg_replace function that causes the apache server to crash!  This crash is due to the thread stack size being inadequately set on the Windows Apache configuration and can be adjusted as described by one of the commenters of the bug:

[2011-09-29 12:35 UTC] ferenczy at volny dot cz
Better way to alter Apache stack size is using the ThreadStackSize directive in the Apache's configuration file (httpd.conf). There is a description of the ThreadStackSize directive in Apache's documentation: http://httpd.apache.org/docs/2.2/mod/mpm_common.html#ThreadStackSize

So increase of Apache stack size might looks like this (lines from httpd.conf):

<IfModule mpm_winnt_module>
   ThreadStackSize 8*1024*1024
</IfModule>

It sets Apache stack size to 8 MB, so it's the same as a default value on Linux.

A google search of the “preg_replace crashing apache” helped solidify this as being the issue with a similar resolution from a question on stackoverflow titled: How do I increase the stack size for Apache running under Windows 7?.  After following Dawid Ferenczy proposed solution, I was successful in running the Magic 360 product within my development environment.

Advertisements

On the XAMPP War-Path…

Pulling my head out of the Windows stack for a while, not that ASP.NET doesn’t work for me – it does; I’m simply tasked to support another stack.  A world somewhat foreign to me.  The world of Apache, MySQL, and PHP.  Not sure what the X and P surrounding the AMP stand for if that’s any indication to how new I am at this.

So I downloaded XAMPP and installed it on my Windows 7 64bit OS.  I didn’t run anything as a service because I didn’t want to add additional processes to my start-up routine.  So I tried to fire up the Apache service from the XAMPP Control panel (v.3.0.12) and it starts and immediately shuts down.  I have my suspicions that it may be conflicting with my IIS utilizing port 80.  So I step into the config file (httpd.conf) and change the port and now I’m up and running it appears.

image

If you are a XAMPP guru or even a PHP guru, let me know as I’m about to perform the equivalent of swimming across the English Channel and would like a personal floatation device to keep me bouyed in this endeavor.