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?
- PHP Workers: Cloudways vs. Kinsta vs. Siteground
- What Happens When You Don’t Have Enough PHP Workers?
- How to Optimize Your Site’s PHP Workers
- PHP Workers With Cloudways
- Conclusion
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.
Host PHP Websites with Ease [Starts at $11 Credit]
- Free Staging
- Free backup
- PHP 8.0
- Unlimited Websites
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 in 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, and 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 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.
PHP Workers: Cloudways vs. Kinsta vs. Siteground
Here is a brief comparison of Cloudways vs Kinsta, and Siteground as Hosting providers and how each of them works. Also, If you are looking for a Siteground alternative and a cPanel alternative, You have multiple choices to choose from.
Cloudways | Kinsta | Siteground | |
Support | Supports all kinds of PHP-based applications. | WordPress-only platform. Forget about using any other PHP-based application. | WordPress-only platform. |
PHP Workers | Offers unlimited PHP workers. You can adjust them according to your website’s traffic and performance. | Starts from 4 workers and goes up to 16 workers with an enterprise plan. | Offers 4 PHP workers with their enterprise plan. |
Disk Space | Starts from 20GB to 3840GB. More storage is available on custom plans. | Offers 10GB to 250GB of Disk space | Offers 16GB to 128GB of disk space. |
Bandwidth | 2GB to 20TB | Unmetered, but monthly visits are very limited | Unlimited |
Servers | Choose between DigitalOcean, AWS, and Google Cloud Platform | Only runs on Google Cloud C2 | Only runs on Google Cloud C2 |
CDN | Offers Cloudflare CDN | CDN bandwidth is limited | Offers Cloudflare CDN |
Caching | Varnish, Redis, Memcached | Bytecode, Object Page, CDN | Memcached, GrowBig+ |
Get Unlimited PHP Workers With Cloudways
Join the only major managed host that offers up to 6000 PHP workers per site, so you don’t have to worry about getting short of PHP workers ever
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.
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.
1) System Cache
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.
2) 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.
3) Use Plugins When Needed
If you’re looking to perform tasks on your websites, such as including JavaScript or CSS, you might not require a plugin for that. Instead, you can include code specific to your theme’s PHP benchmarks templates or a style.css file with a child theme.
As much as possible, distance yourself from code bloat by not installing pointless plugins
4) Choose a Performance-Focused Host
It is recommended to opt for a hosting provider that offers you ample PHP workers, so you don’t have to worry about the number of PHP workers again. Focusing on the importance of PHP workers, Cloudways offers its users up to 6000 PHP workers per site, unlike other hosting providers.
High-Performance CPU
PHP workers use CPU resources to execute code. A speedier CPU implies quicker code execution. At Cloudways, we use the fastest cloud servers: Digital Ocean, AWS, and GCP.
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 (more than all its competitors) at the user’s request.
Supercharged Managed PHP Hosting – Improve Your PHP App Speed by 300%
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. Also, When choosing a learning management system hosting, it is important to make sure that the provider offers enough PHP workers to meet the requirements of your LMS.
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 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.
Conclusion
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. Use our Pricing calculator to determine web hostingcosts.
Q. How many PHP workers do I need?
A: Generally, 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. Luckily, hosts like Cloudways offer up to 6000 PHP workers, freeing you from all such worries.
Q. How can I reduce PHP worker usage?
A) Here’s how you can reduce PHP worker usage:
- Optimize your PHP code to improve its efficiency and reduce the processing time.
- Implement caching mechanisms like opcode caching to store frequently accessed data, reducing the need for repeated calculations and database retrievals.
- Consider offloading time-consuming tasks to background processes or asynchronous systems using technologies like queues or job schedulers
Regularly monitor and analyze your application’s performance to identify bottlenecks and fine-tune your optimizations for better resource utilization.
Q. How do I increase PHP workers in WordPress?
You can adjust the “max_children” setting in your PHP-FPM or web server configuration increase PHP workers in WordPress. But with hosts like Cloudways, you don’t have to worry about reducing the number of PHP workers as it allows a max of 6000 PHP workers per site, unlike other hosts like Kinsta & Siteground, which limit their users to only 4 PHP workers per site.
How can I make PHP faster?
You can use native PHP functions, add CDNs for fast content delivery, use caching systems, use JSON except for XML, and configure OPcache, PHP-FPM, and Memcached properly. You can also close the DB connection and limit the DB hits.
Shahzeb Ahmed
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]