从 PHP 外部打印 PHP 运行调用堆栈
PHP 中是否有通过给定 PID 进行运行时堆栈跟踪功能? (对于那些也写Java的人来说,我指的是jstack。)
我有几个PHP后台进程,它们偶尔会在一些未知的行上冻结。我可以简单地杀死他们并重新启动,但这并不能阻止它再次发生。
有没有一个 API 能够监视堆栈并告诉我们?就像 JDK 提供的 jstack 实用程序一样?
Is there any runtime stack trace feature in PHP, by a given PID of it?
(For whom also write Java, I mean jstack.)
I got few PHP background process that they are freeze once a while on some unknown lines. I can simply kill them all and restart but that don't prevent it happen again.
Is there a API able to spy the stack and tell? like the jstack utility provided from JDK?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在调试未知错误方面,您有几种选择。
--enable-debug
配置 linux 和 PHP。Xdebug
使用
gdb
运行崩溃的文件并分析回溯。--enable-debug
配置 PHP、运行Apache
的 Linux 机器以及强烈的愿望/能够理解软件在较低级别上的工作方式。Apache
运行gdb
:gdb /usr/lib/httpd
(gdb) 运行 -X
...现在,在您的浏览器中 - 正常访问崩溃的页面并切换回
gdb
:(gdb) 回溯
...将打印完整的回溯
gdb
运行脚本本身:(gdb) 运行 /path/to/the/script.php
(gdb) 回溯
...将打印完整的回溯
gdb
信息,请查看 快速参考指南。创建自定义错误处理程序 当抛出错误时打印堆栈跟踪。
require('ErrorHandler.php');
添加到页面顶部,它就会自动注册以处理任何错误。当然,请务必更新包含路径以指向实际文件。错误处理程序.php:
You have a few options in terms of debugging unknown errors.
--enable-debug
.Xdebug
Use
gdb
to run the file that crashes and analyze the backtrace.--enable-debug
, a linux machine runningApache
, and a strong desire/ability to understand the way software works on a lower-level.gdb
withApache
:gdb /usr/lib/httpd
(gdb) run -X
... now, in your browser - access the page that crashes as normal and switch back to
gdb
:(gdb) backtrace
... the full backtrace will be printed
gdb
to run the script itself:(gdb) run /path/to/the/script.php
(gdb) backtrace
... the full backtrace will be printed
gdb
info, check out the quick-reference guide.Create a custom error handler that prints the stack trace when an error is thrown.
require('ErrorHandler.php');
to the top of your page and it should auto-register itself to handle any errors. Be sure to update the include-path to point to the actual file, of course.ErrorHandler.php: