Skip to content
hostcomplex

PHP Workers and Speed

Maarten Soetens 3 min read

What a PHP Worker Is

PHP workers are the separate processes that run PHP code to build dynamic pages on a server. A worker is a running copy of the PHP runtime that waits for a request, handles it and then becomes free for the next one. Most PHP sites run a pool of workers, and the pool size limits how many dynamic pages the server can build at the same moment.

When a visitor requests a page that PHP must generate, the web server hands the request to a free worker. The worker runs the code, which often queries a database, and returns the result. Only then does the worker become available again.

Why Requests Queue When Every Worker Is Busy

Workers are a fixed resource. If every worker is busy with slow requests, new requests cannot start immediately and wait in a queue. A short wait goes unnoticed, but a long queue makes time to first byte grow. When waits exceed a configured limit, the visitor sees an error page or a timeout.

Total capacity is roughly the number of workers divided by the time each request takes. Five workers that each spend two seconds on an uncached page can complete about 2.5 pages per second. A sudden burst of 20 visitors per second would queue far behind that capacity, and the queue would keep growing for as long as the burst lasted.

How Caching and Slow Code Change Capacity

Requests that never reach a worker cost little capacity. A cached page served directly by the web server or a caching layer is one example. This is why a site can handle heavy traffic when most pages are cached, but struggle when every request is unique, as with personalized pages or search results with unusual parameters.

Slow database queries and heavy plugins also keep workers occupied for longer. A single slow query can tie up a worker far longer than the page should need, reducing the capacity of the whole pool. Memory is a limit too: each worker uses RAM, so the pool size is bounded by available memory. Adding too many workers can push the server into swapping memory to disk, which slows everything down.

A Crawler Hitting Uncached Search Pages

Imagine a site with a search feature where each result page is generated fresh with PHP. An automated crawler requests thousands of unusual search addresses in a few minutes. Each request occupies a worker, and real visitors loading ordinary pages now wait behind the crawler's requests.

The site looks slow to its human visitors even though most of its pages are fine. Recognizing that the bottleneck is the worker pool, rather than the code of any single page, explains why the problem appears only during bursts like this one. The general role of server capacity is covered in hosting and website speed.

Frequently asked questions

What happens when PHP workers run out?

New requests wait in a queue. If the wait becomes too long, the server may return a gateway error or a timeout, or pages may load very slowly. Visitors then see an error page, even though the server itself is still running and static files such as images may still load normally.

Do more PHP workers make a site faster?

Not necessarily. More workers allow more requests to run at once, but each one uses memory and CPU. If the server lacks spare resources, extra workers can make everything slower. Reducing the time each request takes, and serving cached pages where possible, usually gives a bigger improvement.

  • Two-Factor Authentication

    Two factor authentication hosting adds a second check to control panel, domain and CMS logins. Learn which methods are strongest and why 2FA helps.

  • What Is an A Record?

    What is an A record? Learn how this DNS record maps a hostname to an IPv4 address, why domains use several A records and the root and www pattern.

  • Billing and Automation Platforms

    What is WHMCS? Learn how this commercial billing and automation platform helps hosts sell plans, collect payments and create accounts automatically.