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

1

22

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

Leotaleotard answered 20/2, 2011 at 17:58 Comment(2)
Needs more info. What crashes where exactly with what error message?Gignac
No crash, just blank page sent to browser by Apache. I think it is stack overflow because it only happens when I have zend_extensions loaded for debugging, which increases the stack depth. Just before application under apache gives up, the stack depth is 99, not counting zend. No error message.Leotaleotard
P
76

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! :)

Perdu answered 29/9, 2011 at 12:44 Comment(6)
This worked for me, I didn't even have errors in my logs, just that the process exited successfully.Shape
@Freek, What's your Apache LogLevel?Eating
I have this notice, but increasing ThreadStackSize didn't work for me... There is one specific application which breaks my Apache and I can't figure it out :/Curtate
Well, there are multiple reasons for that. You failed to configure it properly (didn't restart Apache, used a wrong configuration file, etc.), the application needs even more than 8 MB stack (or whatever you've configured) or it may even contains an infinite loop, so it will eat the stack, no matter how big it is. Or you may have a completely different root cause of the problem. Try to localize the part of the application which is causing the issue.Ivette
This fixed my issue! I ran into a stack overflow with Symfony on Windows. I had no errors in Symfony logs, or Apache, just info that Apache restarted, but Windows logs were showing that httpd.exe was crashing. After a lot of trial & error I determined I had too many route parameters throughout the application but I set ThreadStackSize and it's all good!Consul
What is ThreadStackSize for? Why we need to put that? Sorry, I can't still understand its technicalities.Glamour

© 2022 - 2024 — McMap. All rights reserved.