Tech lesson Pinned

Zombie PHP Processes: Why Your Server Slows Down and How to Fix It

Zombie PHP processes are processes that should have ended but are still on your server. This short video shows where they come from, what they do to your site, and 5 steps to stop them.

What is a zombie PHP process?

A process that should have ended, but is still on the server. There are two kinds:

  • Dead but not removed (Z, defunct): it finished its work, but the parent process did not collect its exit status. It keeps a place in the process table.
  • Stuck: a slow query or a call with no timeout. It keeps eating RAM and CPU.

Where do they come from?

  • A slow database query
  • An external API call with no timeout
  • An infinite loop in the code
  • A Cron job that starts again before the last run ends
  • A queue worker forgotten after a deploy

What happens to the server?

Each zombie holds a worker and does not give it back. When all workers are taken (pm.max_children), new visitors wait, then see 502 Bad Gateway or 504 Gateway Timeout. RAM and CPU fill up, the site stops, and you lose visitors and sales.

The fix in 5 steps

  • Find them: run ps -eo pid,stat,etime,cmd | grep php and look for state Z or a process running for hours.
  • Set a time limit for every request: request_terminate_timeout = 60s in the PHP-FPM pool and max_execution_time = 60 in php.ini.
  • Renew workers: pm.max_requests = 500. For a quick clean-up now: sudo systemctl restart php8.3-fpm (use your PHP version).
  • Fix Queue and Cron: run php artisan queue:work --timeout=60 --max-time=3600 under Supervisor, and add ->withoutOverlapping() to scheduled commands.
  • Monitor and alert: get an alert when RAM or the number of PHP processes goes high, before visitors feel it.

A server with no zombies is a fast and stable site. Need help with yours? Talk to 9Website.

All stories