Start with load average, not CPU percentage
uptime. You get three numbers: load averages over 1, 5, and 15 minutes. On a single-core VPS, a load average of 1.0 means the CPU is fully occupied. On a 4-core server, a load of 4.0 means the same thing. If your 1-minute average is significantly higher than the 15-minute average, something started recently and is still running. If all three numbers are high and roughly equal, the problem has been going on for a while.
Load average alone does not tell you whether the bottleneck is CPU or disk I/O. For that, run top and look at the %wa (I/O wait) value in the header. If %wa is low and one or two processes show high %CPU, you are looking at a CPU-bound problem, which is exactly the stuck-PHP-process scenario.
Find the process that is burning CPU
top, press P to sort by CPU usage. Often you will see a single php-fpm or lsphp worker sitting at 90-100% CPU. Note its PID (process ID) and the TIME+ column, which shows cumulative CPU time. A PHP-FPM worker that has accumulated minutes of CPU time is almost certainly stuck in a loop or waiting on something that will never return.
If you prefer a one-shot snapshot instead of an interactive view, use ps:
BASH
ps aux --sort=-%cpu | head -20php-fpm: pool entries or lsphp processes. The TIME column tells you how long the process has been consuming CPU. A healthy PHP request finishes in well under a second of CPU time. A worker showing 3, 5, or 15 minutes of accumulated CPU time is not normal.
Figure out what the stuck process is doing
strace to see what system calls the process is making in real time. This tells you whether it is stuck in a tight loop, waiting on a network socket, or hammering the filesystem.
BASH
strace -p 12345 -e trace=network,read,write -f12345 with the actual PID. Common patterns:
- Rapid repeated
readandwritecalls on the same file descriptor often means an infinite loop in PHP code, typically awhile(true)with no exit condition or a recursive function that never terminates. - Blocking on
pollorrecvfromwith no activity suggests the process is waiting on an external API call or a database query that has hung. The PHP script itself may not be looping, but it is holding a worker slot hostage while it waits. - Repeated
lstatoropencalls on thousands of files can indicate a plugin or script scanning the entire filesystem, which happens with some poorly written WordPress backup or security plugins.
Ctrl+C to detach strace without killing the target process.
If strace is not installed, you can still get useful information from /proc/PID/cmdline to see which PHP script was invoked, and /proc/PID/fd/ to see which files and sockets are open.
Check PHP-FPM status for the full picture
/etc/php-fpm.d/www.conf or /etc/php/VERSION/fpm/pool.d/www.conf, depending on your distro) with the pm.status_path directive.
Once enabled, you can query it locally:
BASH
curl 'http://127.0.0.1/status?full'request duration measured in hundreds of seconds or more. The script field tells you which PHP file is responsible. This is often the fastest way to identify the guilty script without needing strace at all.
For a deeper look at how PHP-FPM pool exhaustion works and how stuck workers cascade into site-wide outages, see Unraveling PHP-FPM Pool Starvation in High-Concurrency WordPress Hosting.
Kill the stuck process and verify recovery
ps output before proceeding.
Send a SIGTERM first, which gives the process a chance to clean up:
BASH
kill 12345ps aux | grep 12345. If it is still there, it is ignoring the signal, and you need SIGKILL:
BASH
kill -9 12345uptime again. If load average drops rapidly over the next minute, you found your culprit. The server did not need more CPU. It needed one bad process removed.
Why the process got stuck in the first place
/proc/PID/cmdline and review that file.
External API calls with no timeout. PHP's default socket timeout (default_socket_timeout) is typically 60 seconds, but some HTTP client libraries override this or set no timeout at all. If the remote server never responds, the PHP worker hangs indefinitely. The fix is setting explicit timeouts in the code (cURL's CURLOPT_TIMEOUT, for example).
Database queries that lock and never return. A long-running ALTER TABLE or a deadlocked transaction can cause PHP workers to pile up waiting for MySQL. Check SHOW PROCESSLIST in MySQL to see if queries are stuck in a Locked or Waiting for table metadata lock state.
CLI scripts invoked by cron without max_execution_time. PHP's max_execution_time directive, which typically defaults to 30 seconds for web requests, does not apply to CLI scripts. A cron job running a PHP script via the command line can run forever. If it enters a loop, it will consume CPU until someone kills it or the server runs out of resources.
Prevent it from happening again
max_execution_timeinphp.inicaps how long a web request can run. Make sure it is set to a reasonable value (30 seconds is the common default for web SAPIs). This does not protect against CLI scripts.request_terminate_timeoutin the PHP-FPM pool config forcibly kills a worker that has been handling a single request for longer than the specified duration. This is the more reliable safeguard because it works at the process manager level, not inside PHP itself. Setting it to something like 300 seconds (as an illustrative example) means no single request can hold a worker for more than 5 minutes, regardless of what the PHP code does.
timeout at the shell level:
BASH
timeout 600 php /path/to/script.phpslowlog and request_slowlog_timeout directives in the pool config). It logs a stack trace of any request that exceeds the threshold, which helps you catch problematic scripts before they become fully stuck.
The takeaway
ps, top, or the PHP-FPM status page. If one worker has been running for minutes with near-100% CPU, kill it and watch the load drop. Then trace the root cause in the script, set request_terminate_timeout as a safety net, and save yourself the cost of hardware you did not need.