How do you debug a LONG RUNNING php script?

大城市里の小女人 提交于 2019-12-20 05:43:31

问题


The problem is that the script hangs up after some long time. strace returns something like this and nothing else:

Process 7286 attached - interrupt to quit
restart_syscall(<... resuming interrupted call ...>) = 0
poll([{fd=13, events=POLLIN|POLLPRI|POLLRDNORM|POLLRDBAND}], 1, 0) = 0 (Timeout)
clock_gettime(CLOCK_MONOTONIC, {1817569, 74651533}) = 0
clock_gettime(CLOCK_MONOTONIC, {1817569, 74734744}) = 0
clock_gettime(CLOCK_MONOTONIC, {1817569, 74812047}) = 0
poll([{fd=13, events=POLLIN|POLLPRI|POLLRDNORM|POLLRDBAND}], 1, 1000) = 0 (Timeout)
poll([{fd=13, events=POLLIN|POLLPRI|POLLRDNORM|POLLRDBAND}], 1, 0) = 0 (Timeout)
....

Putting here'n'there debug messages is left as a last resort..

I can run the script with xdebug attached but is there a way to send some POSIX signal to php process which would trigger xdebug to dump current context/stacktrace/localvars?

Is it possible to get 'postmortem dump' of php script?


回答1:


Xdebug does not have functionality for this. Using pcntl_signal and then using xdebug_print_function_stack is an option, but what you can also do is to create a "function trace". This is something that makes Xdebug write every function call to disk as soon as they happen. This should be able to tell you where your script hangs. From what I can see though is that is waiting for IO.

There is more information about function traces at http://www.xdebug.org/docs/execution_trace



来源:https://stackoverflow.com/questions/17648097/how-do-you-debug-a-long-running-php-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!