Tracking down the cause of apache hanging processes
What's the best way of tracking down hanging processes. I have a bunch of new sites using our new CMS system that randomly hang. They use PHP 7.2 and do not seem to die after max execution time.
At first I thought it was persistent PDO database connections in the script, but it still does it after disabling that.
There's nothing in the PHP error log, but in my process list I see
/usr/sbin/httpd -k start starting to use 90% CPU until I kill it. The process numbers aren't always in the apache status but if they are they are "W" statuses. From a user point of view the script does all its execution but it seems to just hang after the last command.
My questions:
1. Why aren't these processes killed off automatically (be it max_execution_time or something else)?
2. What command can I use to find the last script file, PHP code, DB query, that was executed on that process that caused the hang.
lsof | grep {process_number}
will tell me which files were accessed last on the process, but need to narrow it down further.
As far as I can tell the apache access_log doesn't list the process
I'm also using suPHP instead of cgi
-
. Why aren't these processes killed off automatically (be it max_execution_time or something else)?
They aren't being killed off automatically because they're sitting in W - this is a coding issue. What command can I use to find the last script file, PHP code, DB query, that was executed on that process that caused the hang.
I don't think you'll be able to get that detailed with lsof -p but you might try strace to see the specific system calls.0 -
Thanks, but with regard to the first point about being a coding issue. We switched to from suphp to fcgi and the problem went away suddenly. Surely if it was a coding issue, this wouldn't be the case. 0 -
Hi @Gareth-AWD Because FCGID has a different process handling method it may cover up the fact that connections weren't closing properly before. So the problem is most likely still there, just fcgid helps keep it maintainable due to its own configuration. I am glad though to hear things are resolved for you now. You can read in more depth about fcgid here: mod_fcgid - Apache HTTP Server Version 2.5 Thanks! 0 -
Hi Lauren, Thanks for clarifying it. Obvious concerned there may be an issue in the code somewhere. The code does check and create a new folder on the system with PHP mkdir and chmod, this is the only thing I can think of that may cause a wait issue? Is that something that may cause such an issue. It does odd thought the same code running on another server with suPHP does not exhibit the issue. 0 -
Hi @Gareth-AWD My assumption based solely on the description of the issue is that it sounds a lot like the connections aren't being closed properly, this would leave them in the W state and is almost always a coding issue. If you're using the same code on a different server with the same configuration then it is quite possible it could be something entirely different. To find out though you'd most likely want to involve your system administrator. If you think it's something specific to cPanel, please feel free to open a ticket and add both the working + non-working servers so we can compare. 0
Please sign in to leave a comment.
Comments
5 comments