Reputation: 1482
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
Upvotes: 0
Views: 3322
Reputation: 99328
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.
Update 2
It looks like you can now debug php-cli with dbg, too.
Upvotes: 3
Reputation: 404
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:
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 ;)
Upvotes: 2
Reputation: 53850
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 ;)
Upvotes: 2