简体   繁体   English

如何对PHP进程进行故障排除

[英]How to troubleshoot PHP processes

I've built a script in PHP for a small shop that does a few things. 我已经在PHP中为一家做一些事情的小商店构建了一个脚本。

Initiate a DB connection, and query the DB a couple times. 启动数据库连接,然后查询数据库两次。 Read/Write Sessions Make a request to PayPal PDT with fsockopen() parse the results save the order to db 读/写会话使用fsockopen()向PayPal PDT发出请求,解析结果,将订单保存到db

After some testing, the server stopped loading. 经过测试后,服务器停止加载。 Support let me know that there were 20 PHP processes running (which was the limit) For some reason, they are not closing properly 支持让我知道有20个PHP进程正在运行(这是限制)由于某种原因,它们无法正常关闭

USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
bobbysue 970 0.0 0.1 23836 8708 ? S 15:46 0:00 /usr/local/bin/php5.cgi index.php
bobbysue 1574 0.0 0.1 23836 8708 ? S 15:47 0:00 /usr/local/bin/php5.cgi index.php
bobbysue 2328 0.0 0.1 23840 8708 ? S 15:47 0:00 /usr/local/bin/php5.cgi index.php
bobbysue 4031 0.0 0.1 23836 8704 ? S 15:49 0:00 /usr/local/bin/php5.cgi index.php
bobbysue 7112 0.0 0.1 23836 8708 ? S 15:51 0:00 /usr/local/bin/php5.cgi index.php...

1) How can I troubleshoot my script to see where the problem might lie? 1)如何解决脚本问题,以查看问题所在? 2) How do I make sure processes that startup get terminated properly? 2)如何确保启动过程正确终止? Thanks Rich 谢谢Rich

You can use a PHP debugger. 您可以使用PHP调试器。

DBG is a pretty good one. DBG是相当不错的。 I use PHPEd, but I believe DBG will work other ways too. 我使用PHPEd,但我相信DBG也会以其他方式工作。

http://www.php-debugger.com/dbg/ http://www.php-debugger.com/dbg/

http://www.php-debugger.com/dbg/installation.php http://www.php-debugger.com/dbg/installation.php

http://www.nusphere.com/products/php_debugger.htm http://www.nusphere.com/products/php_debugger.htm

There are a few other decent free or near-free PHP debugging options: 还有其他一些不错的免费或近乎免费的PHP调试选项:

http://www.google.com/search?client=opera&rls=en&q=php+debugger&sourceid=opera&ie=utf-8&oe=utf-8 http://www.google.com/search?client=opera&rls=zh-CN&q=php+debugger&sourceid=opera&ie=utf-8&oe=utf-8

Or, if these are daemon processes, or not running in a browser, you will likely have to go with writing info to a log file. 或者,如果这些是守护进程,或者未在浏览器中运行,则可能必须将信息写入日志文件。 I am not sure if they can be debugged - check google. 我不确定是否可以调试-检查Google。

Edit 编辑

Suggested from comment, XDebug looks pretty good too. 从评论中可以看出,XDebug看起来也不错。

http://xdebug.org/docs/ http://xdebug.org/docs/

Update 2 更新2

It looks like you can now debug php-cli with dbg, too. 看来您现在也可以使用dbg调试php-cli。

LOP. LOP。

Lots of print statements. 很多印刷声明。 Find out where the app is hanging and deal with it there. 找出应用程序的挂起位置并在那里进行处理。 you can have the script write to a log file if it is disconnected from the terminal/apache process. 如果脚本与终端/ apache进程断开连接,则可以将脚本写入日志文件。

Of course a debugger works well for this too ;) 当然,调试器也可以很好地工作;)

I'm using Xdebug with exection trace, very easy to setup and use 我正在使用带有执行跟踪的Xdebug,非常容易设置和使用

It could take some time to generate the trace, and it get's massively long, but if one succeeds do isolate the code that one suspects is behaving badly it easier. 生成跟踪可能需要一些时间,而且跟踪的时间非常长,但是如果成功,请隔离一个可疑行为严重的代码,会更容易。 Xdebug and execution trace Xdebug和执行跟踪

Another cool thing is that you can to performance checking and see where in the code the zend engine spends a long time: 另一个很酷的事情是,您可以进行性能检查,并查看zend引擎在代码中花费的时间很长:

Xdebug and Profiling Xdebug和性能分析

There are a lot of tutorials on how to use Xdebug out there on google. 有很多关于如何在Google上使用Xdebug的教程。

In general when using sockets on PHP it's a lot that could go wrong. 通常,在PHP上使用套接字时,可能会出错。 Depending on the server the scripts run on and how php it's configurated, does the targeted server send a correct answer back, do you need to set a timeout? 根据运行脚本的服务器以及php的配置方式,目标服务器是否会发送正确的答案,是否需要设置超时时间? Check that you're following the API of paypal. 检查您是否遵循贝宝的API。

If it's an external / environment issue, you might end up spending to long time debug your otherwise flawless code ;) 如果是外部/环境问题,那么您可能最终会花费大量时间来调试您本来没有缺陷的代码;)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM