如何对 PHP 进程进行故障排除
我用 PHP 为一家小商店构建了一个脚本,可以做一些事情。
启动数据库连接,并查询数据库几次。 读/写会话 使用 fsockopen() 向 PayPal PDT 发出请求 解析结果 将订单保存到数据库
经过一些测试后,服务器停止加载。 支持人员让我知道有 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) 如何对我的脚本进行故障排除以查看问题可能出在哪里? 2)如何确保启动的进程正确终止? 谢谢 富有的
I've built a script in PHP for a small shop that does a few things.
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
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
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?
2) How do I make sure processes that startup get terminated properly?
Thanks
Rich
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用 PHP 调试器。
DBG是一个相当不错的。 我使用 PHPEd,但我相信 DBG 也能以其他方式工作。
http://www.php-debugger.com/dbg/
http://www.php-debugger.com/dbg/installation.php
http://www.nusphere.com/products/php_debugger.htm
还有一些其他不错的免费软件或近乎免费的 PHP 调试选项:
http://www.google.com/search?client=opera&rls=en&q=php+debugger&sourceid=opera&ie=utf-8&oe= utf-8
或者,如果这些是守护进程,或者不在浏览器中运行,您可能必须将信息写入日志文件。 我不确定它们是否可以调试 - 检查谷歌。
编辑
根据评论建议,XDebug 看起来也不错。
http://xdebug.org/docs/
更新 2
看起来像你现在也可以使用 dbg 调试 php-cli。
You can use a PHP debugger.
DBG is a pretty good one. I use PHPEd, but I believe DBG will work other ways too.
http://www.php-debugger.com/dbg/
http://www.php-debugger.com/dbg/installation.php
http://www.nusphere.com/products/php_debugger.htm
There are a few other decent free or near-free PHP debugging options:
http://www.google.com/search?client=opera&rls=en&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.
Edit
Suggested from comment, XDebug looks pretty good too.
http://xdebug.org/docs/
Update 2
It looks like you can now debug php-cli with dbg, too.
洛普。
很多打印语句。 找出应用程序挂起的位置并在那里进行处理。 如果脚本与终端/apache 进程断开连接,则可以将脚本写入日志文件。
当然,调试器也可以很好地解决这个问题;)
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.
Of course a debugger works well for this too ;)
我正在使用带有执行跟踪的 Xdebug,非常容易设置和使用
它可能需要一些时间来生成跟踪,并且它会变得非常长,但如果成功,请隔离人们怀疑行为不良的代码,这会更容易。
Xdebug 和执行跟踪
另一个很酷的事情是,您可以进行性能检查并查看代码中 zend 的位置引擎花费了很长时间:
Xdebug 和 Profiling
有很多关于如何使用 Xdebug 的教程在谷歌上。
一般来说,在 PHP 上使用套接字时,很可能会出错。 根据脚本运行的服务器以及 php 的配置方式,目标服务器是否发回正确的答案,是否需要设置超时? 检查您是否遵循 paypal 的 API。
如果这是外部/环境问题,您可能最终会花费很长时间来调试原本完美的代码;)
I'm using Xdebug with exection trace, very easy to setup and use
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
Another cool thing is that you can to performance checking and see where in the code the zend engine spends a long time:
Xdebug and Profiling
There are a lot of tutorials on how to use Xdebug out there on google.
In general when using sockets on PHP it's a lot that could go wrong. 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? Check that you're following the API of paypal.
If it's an external / environment issue, you might end up spending to long time debug your otherwise flawless code ;)