Debugging hung php

I have a php web application that sometimes hangs. When I go to the page, it just sits there, trying to load for hours, although the maximum execution is 210. This application uses curl at the proxy to download files. An error report is set for everyone, but it does not matter, since the page is empty and hanging.

I cannot find anything while debugging a hovering PHP process.

+4
source share
5 answers

Last I checked, HTTP / IO operations occur outside of php time, so it is possible that CURL is dying or shutting down.

Its IO, so php just throws it into some system library and then calls “select” to wait for it to return.

If he does not return. The php code will not even loop and therefore will not even know that it will not return.

+2
source

I would bet that it is a curl. I had a similar problem a few years ago with a special curl option that I added that hung a script. I would like me to remember exactly what the problem is, but I believe that in the end, this curl was linked to the wrong library below. ( edit ), I'm sure it was an SSL library in my case, this curl used an older version of openssl.

I suggest first removing all calls to curl_setopt() , and then adding them back to see if this error can be isolated. I think if you run the equivalent curl command on the command line, you can immediately see the error.

i fixed it by updating the opensl library that curl used.

+1
source

to see what happens behind the scenes, you can install xdebug, then enable profiling (? XDEBUG_PROFILE = 1) ... it will output the log to a file system compatible with kcachegrind / etc ...., which you can use to see where hanging is done.

Of course, this is MOST, probably a twist problem ....

+1
source

Xdebug is a great idea, and if that doesn’t help, I would also recommend starting your web server through ktrace, strace or farms. He shows you exactly what he is doing and where he can be hanging.

It looks like there is a temporary connection problem, or something else that your application relies on is blocked.

If you are using Apache, check out the Apache HTTP Debugging Guide . The manual is a bit * nix-centric, but can be applied to any web server.

In addition to debugging your web server, I also recommend adding checks if your proxy server is constantly updated and the download source is always available. These checks can be added using a tool such as nagios or a third-party service such as Pingdom . Last, but not least, it may be a temporary DNS problem, so you can use IP addresses to connect to the proxy server and download source and / or add monitoring for the DNS service.

NTN

0
source

This will sound weak, but just open the file descriptor at the very beginning of the page request, and then start doing fwrites in /tmp/debug.txt. See where the last will be written, and then start repeating the various values ​​of the variables in the file in this area. Use binary search theory to distribute your characters into finer and finer resolution sections on your code.

 ie $fh = fopen("/tmp/debug.txt", "w"); fwrite($fh, "made it to here 1 \n"); //some code fwrite($fh, "made it to here 2 \n"); //more code fwrite($fh, "made it to here 3 \n"); 
0
source

All Articles