如何增加在 Windows 7 下运行的 Apache 的堆栈大小?
我认为在 Windows 7 下的 Apache 服务器上运行 cakePHP 应用程序时出现堆栈溢出。
I think I am getting stack overflows running a cakePHP application on an Apache server under Windows 7.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
此问题在 Windows 平台上更常见,因为 Apache 的默认堆栈大小较小。 Windows 上的默认堆栈大小为 1 MB,而 Unix/Linux 平台上的默认堆栈大小为 8 MB。这可能是为什么某些脚本(例如 PHP 脚本)在 Linux 上运行正常,但在 Windows 上导致 Apache 崩溃的原因。
此外,崩溃是无声的(分段错误),没有错误消息,Apache 只是停止响应并重新启动子进程。浏览器无法获取数据并呈现空白页面,因此很难确定问题所在。
这是在 PHP 中使用长正则表达式时的常见问题。
Apache 的错误日志中只有一条通知,表明子进程崩溃了:
更改 Apache 堆栈大小的最佳方法是在 Apache 的配置文件中使用 ThreadStackSize 指令。 Apache 的文档中有对 ThreadStackSize 指令的描述: http://httpd.apache.org/docs/2.2/mod/mpm_common.html#ThreadStackSize
因此,在 Windows 上增加 Apache 堆栈大小可能如下所示:
这些行应该放在 Apache 的配置中文件。为简单起见,您可以将其放入httpd.conf。或者更好(但不是必需),将其放入 httpd-mpm.conf 文件中,并在 httpd.conf 中取消注释这一行:
它将 Apache 的堆栈大小设置为 8 MB,因此它与 Linux 上的默认值相同。
并且不要忘记重新启动 Apache! :)
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:
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:
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:
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! :)