[英]Print PHP running call stack from outside the PHP
Is there any runtime stack trace feature in PHP, by a given PID of it? 通过给定的PID,PHP中是否有任何运行时堆栈跟踪功能? (For whom also write Java, I mean jstack.)
(对于谁也写Java,我的意思是jstack。)
I got few PHP background process that they are freeze once a while on some unknown lines. 我没有几个PHP后台进程,它们在某些未知行上偶尔冻结一次。 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? 是否有一个API可以监视堆栈并判断? like the jstack utility provided from JDK?
像JDK提供的jstack实用程序一样?
You have a few options in terms of debugging unknown errors. 在调试未知错误方面,您有一些选择。
--enable-debug
. --enable-debug
进行配置。 Use gdb
to run the file that crashes and analyze the backtrace. 使用
gdb
运行崩溃的文件并分析回溯。
--enable-debug
, a linux machine running Apache
, and a strong desire/ability to understand the way software works on a lower-level. --enable-debug
(运行Apache
的linux机器),并且强烈希望/能够理解PHP在较低级别上的工作方式。 gdb
with Apache
: Apache
运行gdb
: gdb /usr/lib/httpd
(gdb) run -X
gdb
: (gdb) backtrace
gdb
: (gdb) backtrace
gdb
to run the script itself: gdb
来运行脚本本身: (gdb) run /path/to/the/script.php
(gdb) backtrace
gdb
info, check out the quick-reference guide . gdb
信息,请查看快速参考指南 。 Create a custom error handler that prints the stack trace when an error is thrown. 创建一个自定义错误处理程序 ,该处理程序在引发错误时将打印堆栈跟踪。
require('ErrorHandler.php');
require('ErrorHandler.php');
to the top of your page and it should auto-register itself to handle any errors. ErrorHandler.php: ErrorHandler.php:
<?php
class ErrorHandler {
public static function captureError($err_no, $message, $file, $line) {
echo '<strong>Error (#' . $err_no . '):</strong> ' . $message . ' in ' . $file . ' on line #' . $line . '<br />';
debug_print_backtrace();
}
public static function captureException($exception) {
echo '<pre>' . print_r($exception, true) . '</pre>';
}
public static function captureShutdown() {
if (($error = error_get_last()) !== null) {
debug_print_backtrace();
}
}
}
set_error_handler(array('ErrorHandler', 'captureError'));
set_exception_handler(array('ErrorHandler', 'captureException'));
register_shutdown_function(array('ErrorHandler', 'captureShutdown'));
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.