PHP 不处理堆栈溢出?
当我刚刚尝试以下 PHP 代码时,我感到很惊讶:
function foo()
{
foo();
}
foo();
我预计会收到“500:内部服务器错误”。相反,连接立即关闭(没有收到字节),并且日志文件显示 apache 出现段错误。搞什么?这是 PHP 中的已知错误吗?我缺少一些配置选项吗?因为每次意外的堆栈溢出都会导致进程崩溃,嗯……我认为这是非常不可接受的。
I was surprised when I just tried the following PHP code:
function foo()
{
foo();
}
foo();
I expected to get "500: Internal server error". Instead the connection was closed immediately (no bytes received), and the log files show that apache segfaulted. WTF? Is this a known bug in PHP? Are there some configuration options that I'm missing? Because a crashed process for every accidental stack overflow is, well... pretty unacceptable, I think.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
PHP 无法处理这个问题,它只会进入无限循环并产生分段错误。
http://bugs.php.net/bug.php?id=49823
还有
http://www.mail-archive。 com/[电子邮件受保护]/msg128905.html
PHP is not able to deal with this, it will just go into an infinite loop and produce a segmentation fault.
http://bugs.php.net/bug.php?id=49823
also
http://www.mail-archive.com/[email protected]/msg128905.html
避免使用递归函数,它们通常是一个坏主意” 0 riiight:))) 发明它们是因为它是一个坏主意:))...
我建议为调用函数的次数设置一个 hrd 上限。 DO不要使用全局变量(您实际上可能需要调用更多递归函数,为什么会像这样污染全局变量?)。您可以为函数使用额外的参数。
avoid using recursive functions they are generally a bad idea" 0 riiight:))) they were invented because its a bad ideea:))...
I recomment setting a hrd upper-limit on the number of times the functions is called. DO NOT use global variables (you may actually need to call more recursive functions, why pollute the globals like this?). You may use extra parameters for a function
摘自iBlog - Ilia Alshanetsky
Taken from iBlog - Ilia Alshanetsky
我认为这是一个已知的错误。请参阅列表导致 PHP 崩溃的 10 种方法。
I think this is a known bug. See the list Top 10 ways to crash PHP.