Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I increase the stack size for Apache running under Windows 7?

Tags:

I think I am getting stack overflows running a cakePHP application on an Apache server under Windows 7.

like image 820
Stephen Ippolito Avatar asked Feb 20 '11 17:02

Stephen Ippolito


People also ask

What is the default size of the stack?

Stacks are temporary memory address spaces used to hold arguments and automatic variables during invocation of a subprogram or function reference. In general, the default main stack size is 8 megabytes.


1 Answers

This problem happens more often on Windows platform, because of smaller Apache's default stack size. There is 1 MB default stack size on Windows, unlike 8 MB on Unix/Linux platforms. It could be a reason, why some for example PHP scripts works properly on Linux, but cause crash of Apache on Windows.

Furthermore, the crash is silent (segmentation fault), there is no error message, Apache just stops responding and the child process is restarted. Browser gets no data and renders a blank page, so it's a bit difficult to decide what's wrong.

It's a common problem when working with long regular expressions in PHP.

There is one notice in Apache's error log only, which tells, that child process crashed:

Parent: child process exited with status ... -- Restarting 

The best way to alter the Apache's stack size is using the ThreadStackSize directive in the Apache's configuration file. 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 the Apache's stack size on Windows might looks like this:

<IfModule mpm_winnt_module>    ThreadStackSize 8388608 </IfModule> 

These lines should be put in the Apache's configuration file. For simplicity, you could put it to httpd.conf. Or better (but not necessary), put it to httpd-mpm.conf file and in httpd.conf uncomment this line:

Include conf/extra/httpd-mpm.conf 

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

And don't forget to restart Apache! :)

like image 55
David Ferenczy Rogožan Avatar answered Oct 13 '22 19:10

David Ferenczy Rogožan