Running a WordPress site smoothly and efficiently involves understanding technical elements- like PHP memory limits and PHP threads. But what exactly do these terms mean, and how do they impact your WordPress site’s performance?
Think of your WordPress site as a bustling coffee shop. The PHP memory limit is like the storage space for coffee beans, milk, and other ingredients. If the storage is too small, your baristas (PHP processes) will struggle to make drinks efficiently because they keep running out of supplies. On the other hand, PHP threads are like the baristas you have on staff. More baristas mean more drinks can be prepared simultaneously, reducing customer wait times.
This article explains the PHP memory limit and PHP threads, when to adjust them for optimal performance, and how to do this on Kinstas servers.
What is a PHP memory limit?
Every time your site loads a page activates a plugin or uses a theme feature, PHP scripts execute, and they need memory to function properly. The PHP memory limit determines how much memory your WordPress site has access to.
You’ll want a PHP memory limit high enough that your site can handle all its tasks without running into issues like:
- Slow page loads — Not enough memory can slow the execution of PHP scripts, leading to longer page load times.
- Plugin failures — Resource-intensive plugins may not function correctly if they don’t have enough memory.
- White screen of death — When a PHP script runs out of memory, your site may display a blank white screen instead of loading properly.
What are PHP threads?
PHP threads are another crucial component that impacts your WordPress site’s performance. Threads are background processes on a server that manage the execution of the PHP code that powers your site.
In WordPress, these threads are responsible for building pages, processing scheduled tasks, and more. They also generate HTML pages to serve your site’s visitors and determine how many simultaneous uncached requests your site can handle at any given time.
When a visitor accesses your WordPress site, a request is sent to the server, which is then processed by a PHP thread. Several requests can be processed simultaneously if your site has multiple PHP threads. For instance, if your site has two PHP threads and five requests come in simultaneously, two will be processed immediately, while the other three will wait in the queue until the first two have been completed.
This queuing system helps manage traffic, but it also means that insufficient PHP threads can lead to delays and slower response times when multiple requests are made at once.
Managing PHP memory limits
Kinsta’s default PHP memory limit is 256MB, which is more than enough for most WordPress plugins and sites.
It’s also important to know that if you set the limit too high, a misconfigured or broken script can cause serious issues when using too much memory.
When to increase PHP memory limit
Increasing the PHP memory limit could be essential for maintaining the performance and stability of your WordPress site when dealing with resource-intensive tasks.
The most common signs that your PHP memory limit needs to be increased is when you encounter error messages like “Allowed memory size exhausted.” This indicates that the current memory limit is insufficient for executing tasks.
Here is an example of what the error message may look like:
PHP Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 20480 bytes)
This message means that the PHP script attempted to allocate more memory than the allowed 256MB (268,435,456 bytes), resulting in a memory exhaustion error. The script tried to allocate an additional 20KB (20,480 bytes) but ran out of memory.
If your site is hosted on Kinsta, these memory exhaustion errors are logged automatically. You can check for these errors on the MyKinsta dashboard. Navigate to your site and select the Logs tab.
Look for entries that include “PHP Fatal error” and “Allowed memory size exhausted.” These logs will indicate the exact memory limit exceeded and the additional memory the script attempted to allocate.
By monitoring these logs, you can identify if your site frequently hits the PHP memory limit and decide whether to increase the memory allocation to ensure smooth script execution.
How to increase your site’s PHP memory limit
When a site’s PHP memory limit needs to be increased, Kinsta customers can purchase a PHP memory limit add-on.
This add-on increases the memory limit from 256MB to 512MB for $50 per site per month.
To purchase this add-on, please get in touch with the Account Management team via the live chat in MyKinsta dashboard or e-mail us at [email protected].
Managing PHP threads
PHP threads are particularly important for sites that do not cache a lot of their content. The more dynamic a site is, the more PHP threads it will need. Cached content doesn’t require PHP threads; it is only necessary when the site queries the database to get or change information or when it needs to execute other PHP scripts.
This means effective caching can significantly reduce the workload on PHP threads by serving cached content instead of generating it dynamically for each request.
At Kinsta, we prioritize your site’s performance by implementing various technologies to maximize PHP performance. We offer page caching at CDN and server levels, utilize premium servers (C2 and C3D virtual machines) equipped with Google Cloud’s fastest CPUs, and ensure a highly optimized MySQL server hosted locally to reduce network latency and improve data retrieval and processing speeds.
When to add more PHP threads
The number of PHP threads needed depends on several factors, including its reliance on database queries, code optimization, and the type of traffic it receives.
An optimized site with efficient PHP code and database queries will process requests quickly, freeing up PHP threads for the next request.
Dynamic sites like e-commerce stores, forums, learning sites, and membership sites typically require more PHP threads than static, brochure-type sites. Additionally, busier sites usually need more PHP threads to handle increased traffic.
Adding more PHP threads can help manage increased traffic and reduce wait times for processing requests, but it’s essential to balance this with available CPU and RAM resources. If the server does not have enough CPU and RAM to support additional PHP threads, it can create a bottleneck, leading to performance issues.
With Kinsta, you can monitor PHP threads activity using Kinsta’s APM tool to identify performance issues and slow queries.
If your site frequently reaches its PHP thread limit, you may need to add more PHP threads or optimize your site’s code and queries to improve performance.
How to add more PHP threads
To add more PHP threads to your site, you can upgrade your hosting plan or purchase additional PHP threads. Here’s how you can do it:
- Upgrade your hosting plan — Each Kinsta plan has a specific number of PHP threads. Upgrading to a higher-tier plan increases your site’s number of PHP threads. For example, moving from a Single 35k to a Single 125k will increase your PHP threads from two to six.
- Custom plans — For sites with specific needs, Kinsta offers custom plans where you can specify the number of PHP threads required. This is ideal for high-traffic sites or sites with significant dynamic content. Contact the Kinsta sales team to discuss your requirements and get a custom quote.
By increasing the number of PHP threads, you can help your site handle more simultaneous requests, leading to better performance and a smoother user experience.
However, always ensure that your server has enough CPU and RAM resources to support the additional PHP threads to avoid creating performance bottlenecks.
Best practices for PHP resource management
Effective management of PHP resources is crucial for maintaining the performance and stability of your WordPress site.
Here are some best practices to optimize your PHP memory and thread usage:
- Efficient caching — Implementing robust caching mechanisms can significantly reduce the load on PHP threads. By serving cached content to visitors, you minimize the number of requests that need to be processed by PHP threads, freeing them up for more dynamic tasks.
- Optimize code and queries — Ensure your PHP code and database queries are well-optimized. Efficient code execution and streamlined database interactions reduce processing time, allowing PHP threads to handle more requests in less time.
- Upgrade PHP versions — Regularly update to the latest PHP versions, often including performance enhancements and security improvements. Newer versions of PHP are typically faster and more efficient.
- Monitor resource usage — Use tools like Kinsta’s APM or Query Monitor to evaluate resource usage. Monitoring helps identify bottlenecks and inefficiencies in real-time, allowing you to take corrective action promptly.
Summary
Managing PHP resources effectively is crucial for the performance and stability of WordPress sites hosted on Kinsta. This article has explored PHP memory limits and PHP threads, their roles, and how to optimize their usage.
For personalized recommendations or to increase your PHP memory limit or PHP threads, please open a new ticket or email [email protected].
Leave a Reply