PHP Workers and Request Prioritization
In this article we explain the unique way WP Engine handles request prioritization when there is too much uncached traffic for the PHP Workers to handle.
Each uncached page request to your website is handled by a PHP Worker. You can think of these PHP Workers as cashiers in a store: each cashier handles one customer at a time, just as each PHP worker executes the PHP code that makes up a web page when a request comes in.
Due to WP Engine’s proprietary multi-tiered Evercache® system, many page requests are served from cache and therefore many requests are not handled by a PHP worker. Serving a request from cache would be like a customer who comes in to pick up an order that’s already been completed. It’s fast and efficient, and doesn’t burden the cashiers who need to be available for new customers and their unique orders.
When every cashier is occupied with a transaction, a queue of waiting customers is formed. Similarly, when the PHP workers can’t finish requests more quickly than they’re coming in, a backlog is created.
WP Engine Queuing Benefits
Where most hosts simply serves all traffic on a “first come, first served” basis, WP Engine understands that your site needs to reach real users first. On WP Engine, our unique traffic shaping system prioritizes real users above requests from bots, crawlers, and AJAX requests. That means your site will always serve real users first.
Another way to visualize this is to look at the way many stores divide checkout lines into full service, “10 items or less”, and self-checkout lanes. Traffic can be divided and prioritized in ways ensuring that as many transactions as possible can be processed efficiently. In this way the traffic overburdens neither the customers nor the cashiers.
Another dilemma other hosts present is that when a server is barraged with uncached traffic, they simply begin denying all new requests. On WP Engine our system intelligently chooses oldest waiting requests to be rejected. This allows your site to still accept new traffic in the process. That means instead of high traffic simply taking your site down, your site can still support new traffic continuously through it.
WP Engine segments traffic into several queues, the queues then have their own level of priority to feed into the PHP workers. Requests are sorted in the following order:
- Traffic is sorted by account
- When one account (including all environments on it) is getting excess traffic, PHP workers are still available for other accounts (and all of their environments) on the server.
- This means only requests to environments on one account will impact that account’s queue.
- Traffic is sorted by type or source
- Real, human end-user traffic is grouped together in the highest priority queue (most likely to be processed)
- AJAX and XMLRPC request are grouped together in a low priority queue (more likely to be evicted from queue)
- Well-known bot requests are grouped together at in a low priority queue (more likely to be evicted from queue)
This queueing system allows the PHP workers to serve the requests as they come in. If the server can’t immediately process a request, it will prioritize the real end users of your website above anything else.
This structure also means that crawling or remote monitoring services, which operate off of bots, could return errors if their crawl rate is too high and their queue is being impacted. This doesn’t necessarily always indicate an issue with server health.
Our request prioritization and traffic shaping system does a lot of work to protect your site. However, there are some known plugins to steer away from. The following plugins tend to overwhelm your PHP Workers:
- View/Share counter plugins
- Plugins that generate popups
- Ad plugins which hit
These types of plugins tend to trigger large amounts of uncached traffic to your site, which is compounded when your site is already receiving heavy traffic. If possible, we recommend using any caching settings available for these types of plugins, or avoiding use altogether. This will help ensure your site can scale to better support higher traffic.
A more extensive, updated list can always be found in our disallowed plugins guide here.
Too Many Requests
When the all PHP workers and the backlog queue are full, this is where you may begin to see errors such as 504 and 502. There are 3 primary reasons you may see errors due to PHP worker queuing.
NOTE: Bots, AJAX and XMLRPC will see these errors well before real users, due to queue priority.
A 504 error can occur when too many items are in the backlog and items are evicted.
A 502 error can occur when items are taking too long to process and are killed to free up the PHP worker for other requests.
Both issues are typically straightforward to resolve once you’ve identified the source of the troublesome requests. If you see errors such as these on your site and aren’t able to pinpoint the issue, our 24×7 Support team is always standing by ready to help!
- Too many uncached requests
- This is typically accompanied by a 504 error. Learn how to find your access logs to check for a 504.
- Review our guide for triaging 504 errors
- If you have services crawling your website, pause or adjust the crawl delay
- Improve your website’s cacheability
- Uncached requests are taking too long to process
- This is almost always accompanied by a 502 error. Learn how to find your access logs to check for a 502.
- Review our guide for triaging 502 errors
- Troubleshoot your website for slowness
- Optimize your database
- More PHP workers are needed
- If the site cannot be further optimized and all the requests are legitimate, then it seems your business has successfully scaled up! It’s most likely time to upgrade to a larger server with more PHP workers.
- Reach out to your account manager.
NEXT STEP: Learn more about 504 errors