PHP workers are an imperative piece of the high-performance hosting puzzle. Most managed hosting companies offer inflexible hosting plans that can offer extraordinary results for the average website, but spell doom for dynamic sites with parts of the cache bypassing traffic.
As you develop your business and develop more complex websites, an understanding of PHP workers and how they influence website performance becomes crucial. This article will walk you through the basics and offer a few real-world guidelines for common use cases.
- What are PHP Workers?
- Why Do You Need PHP Workers?
- What is the Impact of PHP Workers on Your Application Performance?
- How Many PHP Workers Do You Need?
- What Happens When You Don’t Have Enough PHP Workers?
- How to Optimize Your Site’s PHP Workers
- Choose a Performance-Focused Host
- PHP Workers with Cloudways
What are PHP Workers?
PHP workers are background processes on servers that run PHP code.
They construct pages and handle requests that require backend processing on your website. This technology creates HTML pages to serve your site visitors. PHP workers decide the number of uncached demands that your website can handle at any time. Once a PHP worker has started, it remains diligent until processes are completed or certain conditions are met.
Say Nginx gets a request that PHP should process. It’ll forward the request to PHP-FPM, which can relegate the request to an accessible PHP worker. The PHP worker will execute the PHP code, get the required information from MySQL or Redis, and construct the page output. The page output will, at that point, be passed back to Nginx before being sent back to the browser.
In a nutshell, PHP workers are the server processes that run your source code. Whenever an uncached page receives a request, it’s dealt with by a PHP worker.
Why Do You Need PHP Workers?
The job of PHP workers is to handle any demands that bypass or miss the website’s cache. If a request doesn’t hit the cache, a PHP worker will take over, handle the request and return it to the guest within the form of a web page.
PHP workers handle the data quicker, clearing numerous processes within milliseconds. They allow you to execute simultaneous operations, meaning more client orders can be prepared at once.
It’s important to remember their capacity to function isn’t infinite – it depends on different variables, including the requests, and the server resources available to them, which can decide how many uncached visits/requests your location can handle at a time.
What is the Impact of PHP Workers on Your Application Performance?
Dynamic tasks like a simple stock check for a client can involve complex processes like viewing and posting all earlier orders for that client.
PHP workers play an essential part in stacking the dynamic pages of your website quickly, and thus improving your website’s execution. When utilized appropriately, maintaining an ideal balance between PHP worker usage, code optimization, CPU utilization, they help your website experience minimal to no performance issues.
PHP workers utilize CPU resources to execute code. A quicker CPU helps in a faster code execution, which can upgrade your website’s performance. PHP workers’ effectiveness is heavily dependent on CPU and RAM. Hosting your website on an advanced server with the latest equipment can help you optimize PHP worker utilization.
How Many PHP Workers Do You Need?
PHP workers consistently utilize 80-100% of your available CPU capacity. Complex workloads may only permit 2 PHP workers before devouring all accessible CPUs. In contrast, productive and optimized workloads may permit 4, 6, or 8 workers per core with identical server specs.
Too many workers for the available CPU basically slows everything down as they get lined up, and the CPU spends much of its time switching between tasks, instead of getting the work done. Too few PHP workers per CPU wastes resources, as at some rate of your CPU, remains out of gear instead of getting work done.
While the number of PHP workers you need depends on the complexity of the site, and concurrent requests and traffic, a general guideline is 2 to 4 workers for a static site.
For bigger websites with more dynamic functionality, like ecommerce or discussion forums, 4 PHP workers are usually a good starting point. Again, this number shifts per website as each has its own unique set of themes, plugins, database queries, and cached-to-uncached ratio.
What Happens When You Don’t Have Enough PHP Workers?
For quick and solid website execution, it’s vital that your website has sufficient PHP workers. When the available PHP workers are busy on a website, they start to build up a queue in the background and deal with all requests respectively.
There are a number of distinctive factors that can cause slow page loads or errors. Once you’ve reached the limit of your available PHP workers, the line starts to push out older requests which may result in 504 errors or fragmented requests.
Another common error we face due to the lack of PHP workers is bad gateway errors. These occur after a timeout of 60 seconds within the PHP workers’ queue.
Not only do these errors display a bad user experience, but also they have a negative effect on your site’s SEO.
Stop Wasting Time on Servers
Cloudways handle server management for you so you can focus on creating great apps and keeping your clients happy.
How to Optimize Your Site’s PHP Workers
We’ve explained that PHP workers are foundation processes that create HTML pages with PHP code. The foremost self-evident way to optimize PHP worker utilization is to reduce the sum of CPU and PHP resources required to fulfill requests to your website.
Caching is key to a high-performance website. If a page isn’t serving dynamic, visitor-specific content, it should be cached. Web servers like Nginx and Open-Lite-Speed offer remarkable performance when serving from the cache. Both are competent in dealing with the sum of concurrent activity when PHP processing is kept to a minimum.
When a page is cached, what it’s putting away is pre-prepared HTML, CSS, and JS that’s ready for a browser to utilize promptly. Nginx / OpenLiteSpeed doesn’t have to send anything to PHP for processing to “create” a page. They simply put away a duplicate of the result from the initial time it was created. At this point, it’s rather like serving a totally inactive site.
The blog post you’re currently perusing is the perfect illustration of a page that doesn’t have to be dynamically generated. Like many of our other posts, the content in this post is designed to be static, so there’s no need to spend CPU resources to create identical pages continuously.
Instead, it’s way better to have PHP workers generate the page once and then cache it. Page caching has numerous self-evident preferences over dynamically generating pages with PHP. There are two ways to set up page caching for your website.
- Server-level page caching with Nginx.
- Plugin-based page caching with WP-Rocket.
For extreme performance, we suggest utilizing server-level page caching whenever possible.
Choose Quality Plugins
The number of plugins on your website isn’t as important as the quality of the plugins. In case a plugin hasn’t been updated within the past six months, choose another one that fits the charge.
In case a plugin hasn’t been updated in a long time, there are chances that its code isn’t utilizing the most recent WordPress advancement.
Alternatively, in case a plugin is continually updated every few weeks, there’s a great chance that the engineer is serious about quality, which makes it a great choice for your website.
Use Plugins When Needed
As much as possible, distance yourself from code bloat by not installing pointless plugins
Choose a Performance-Focused Host
PHP Workers with Cloudways
Since every site is built a little differently, the number of PHP workers you need can vary. The best way to find this number is to look at how many PHP workers you’re currently using. Once you get a baseline of how many PHP workers and PHP memory limit you may be using , and what your traffic volumes are, you can plan for future increases. Regardless of the usage and the traffic of a website Cloudways allows a max of 6000 PHP workers per site on the request of the user.
PHP workers for a high traffic ecommerce site:
picclick.co.uk is an ecommerce store established back in 2008. As a high-trafficking ecommerce store that was being accessed from around the world, its need for PHP workers increased. Currently, Picclick uses around 507 – 530 PHP workers to handle the traffic and requests.
Many ecommerce sites can benefit from utilizing 3 static workers per CPU core. If you have a clean code base and aren’t managing too many long-running requests, you need to test your website performance at 4 and 5 workers per core until you discover the sweet spot.
PHP workers for a high-traffic LMS site:
crc.pslms.org Is an LMS that focuses on key topics fundamental to the conduct of clinical research. Managed on Cloudways servers, the LMS sees exceptionally high traffic and uses around 5-10 PHP workers.
Too many users simultaneously active on your LMS site can put a lot of strain on your framework. In these cases, your codebase should be as lean as possible and your website needs to be on a server with a high-performance CPU.
Test static workers at 3 workers per CPU core monitor performance, and if you need more juice, test how your website performs at 4, 5, and possibly even at 6 workers per core.
PHP workers for a high-traffic multisite:
cityscoop.us is a top-ranked website on Google for U.S. local business news. The readers are mostly local businesses and national franchise brands that disseminate content to the search engines through our news network. A highly visited multisite, CityScoop uses around 10-15 PHP workers at max.
With multisite, one site has access to all the resources. So static workers offer optimized performance on both the front and back ends.
As for dynamic workers, start testing them at 5 workers per CPU core. After monitoring performance, test how your website performs at 7, 8, and possibly even at 10 workers per core until you discover the sweet spot.
Cloudways vs Kinsta vs Siteground
Here is a brief comparison of Cloudways, Kinsta, and Siteground as Hosting providers, and how each of them works.
When requests are not properly handled, web pages can malfunction or the server can crash. PHP workers play a vital role when it comes to request handling. Choosing a good hosting provider is also a critical step in managing PHP workers, as every hosting provider offers a different number of PHP workers.
Q. How many PHP workers do I need ?
A: In general, sites with essentially static content do not require numerous PHP workers.
For bigger websites with more dynamic functionality, 4 PHP workers are a good beginning point. However, this may change according to the site’s special set of themes, plugins, database queries, and cached-to-uncached ratio.
Customer Review at
“Cloudways hosting has one of the best customer service and hosting speed”
Sanjit C [Website Developer]
Shahzeb is a Digital Marketer with a Software Engineering background, works as a Community Manager — PHP Community at Cloudways. He is growth ambitious and aims to learn & share information about PHP & Laravel Development through practice and experimentation. He loves to travel and explore new ideas whenever he finds time. Get in touch with him at [email protected]