Insights

Thinking High CPU Means You Need a Bigger Server? Check if a Stuck PHP Process Is the Real Cause

November 18, 2026
0:00
Your monitoring dashboard shows CPU pinned near 100% for the last hour. Sites hosted on the server crawl or time out. The reflex is to open a ticket asking for a bigger plan, more cores, more RAM. Before you spend money, check whether a single stuck PHP process is eating all available CPU. This is one of the most common causes of sustained high load on shared and VPS hosting, and killing one process often brings the server back to normal in seconds.
SSH into the server and run 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.
Inside 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 -20
This lists the top 20 processes sorted by CPU usage, highest first. Look for php-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.
Once you have the PID, you can attach 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 -f
Replace 12345 with the actual PID. Common patterns:
  • Rapid repeated read and write calls on the same file descriptor often means an infinite loop in PHP code, typically a while(true) with no exit condition or a recursive function that never terminates.
  • Blocking on poll or recvfrom with 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 lstat or open calls 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.
Press 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.
If PHP-FPM is running and you have the status page enabled, it gives you a view of every active worker, what script each one is executing, how long it has been running, and its current state. The status page is typically configured in the pool config file (often at /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'
The exact URL depends on your web server configuration. In the output, look for workers with a 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.
Once you have confirmed which process is stuck and what it is doing, kill it: Warning: Make sure you are killing the correct PID. Killing the PHP-FPM master process instead of a worker will restart all PHP processing on the server, which drops every active request. Double-check the PID against your ps output before proceeding. Send a SIGTERM first, which gives the process a chance to clean up:
BASH
kill 12345
Wait a few seconds and check if the process is gone with ps aux | grep 12345. If it is still there, it is ignoring the signal, and you need SIGKILL:
BASH
kill -9 12345
After killing the process, run uptime 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.
Killing the process fixes the symptom. The cause is still there and will come back. Common root causes: Infinite loops in application code. A WordPress plugin update introduces a bug, a custom theme has a recursive function with no base case, or a WooCommerce hook triggers itself. Check the script path from the PHP-FPM status output or from /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.
Two PHP-FPM directives act as safety nets:
  • max_execution_time in php.ini caps 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_timeout in 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.
For CLI cron jobs, wrap them with timeout at the shell level:
BASH
timeout 600 php /path/to/script.php
This kills the process after 600 seconds no matter what. Also consider enabling the PHP-FPM slow log (slowlog 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.
High CPU on a hosting server does not automatically mean you need a bigger plan. Before upgrading, spend two minutes with 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.

Join My Newsletter & Get Updates!

Get notified whenever a new technical guide, server infrastructure breakdown, or personal reflection goes live, plus a curated weekly digest.