This website uses cookies

Our website, platform and/or any sub domains use cookies to understand how you use our services, and to improve both your experience and our marketing relevance.

PHP Memory Limit and Why Do You Need Them?

Updated on May 24, 2022

4 Min Read
php-memory-limit

The PHP memory limit is the maximum server memory each PHP script can extend. Per the PHP documentation: “This sets the memory in bytes that a script is allowed to designate. This makes a difference in preventing ineffectively composed scripts from eating up all accessible memory on a server.”

The memory limit setting fixes a memory size for executing a script. It prevents ineffectively coded scripts on the server that designate superfluous space, thus sparing server memory during large-scale utilization of the application.

What is the PHP Memory Limit?

The PHP memory_limit is per-script, just as a standard memory limit that is enough for any web application. A lower setting of 128M. If PHP scripts attempt to utilize more than 128M, those scripts would presently return memory limit surpassed errors.

Set the memory limit set by executing the phpinfo() function to see the memory constrain and plan your server setting according to the value. The server administrator can set a memory limit from -1—no memory assignment to any measure.

PHP scripts are tiny. Every individual script should only take up a small amount of RAM, unless you’ve got an unusual application that needs more resources in one script than most programs will ever take in their entirety. These kinds of plugins certainly exist, but they’re uncommon.

Why Is There a Memory Limit?

Increasing the memory of each process can decrease the number of concurrent processes that can run. PHP processes are critical to the maximum number of page requests you’ll serve at any given time.

When PHP processes get overloaded, the memory limit, servers have to force stop before they completely crash, or all your distributed resources for the month get consumed.

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 Does PHP Memory Limit Relate to Performance?

Say 3 PHP scripts are utilizing 100 MB of memory each at the same time. That would add up to 300 MB of memory utilization, and a PHP limit of 128 MB wouldn’t be enough. The RAM depends on the accessibility of the data required to run a preparation or script. So if you know you’ll require more, 256 MB should cover the heaviest plugins.

Be careful when using plugins that need additional memory. Some web hosts set the PHP memory limit exceptionally low, so that can cause the mistake to appear even when you’re not installing a power-hogging application.

How to Increase the PHP Memory Limit

If your website’s needs necessitate increasing the memory limit, to complete a process, for instance, you’d need to create a php.ini (phprc) file and increase the limit there.

But Cloudways users don’t need to edit the PHP. ini file and wp-config file. They can just change the value from within the application settings using the Cloudways Platform.

cloudways-php-memory-limit

The PHP Memory Limit with Cloudways

Every site is built to serve a different purpose. You can vary the PHP memory limit you need based on this and the hosting environment you’re using. Once you get a baseline on your traffic volumes and the memory limit your application is using, you can plan for scalability in the future.

Cloudways does not limit you to a fixed memory limit size. Just like with PHP workers, we let the user increase the memory limit according to their needs.

PHP memory limit for a high-traffic ecommerce site:

Learning the Harp is a high-traffic ecommerce store accessed from around the world. Currently, it uses 6000 MBs of PHP memory to handle the traffic and requests.

When your website is hosted on one server, each client who visits it sends requests to that same server. This implies that when your website experiences high levels of traffic, the time it takes to handle each request increases, slowing down stack times for all of them. An increased PHP memory limit helps servers to handle requests more efficiently.

PHP memory limit for a high-traffic LMS site:

Pittsburgh Fresh is an LMS based in Pittsburgh, PA, that focuses on delivering fresh, healthy and convenient meals. Managed on Cloudways servers, the LMS sees exceptionally high traffic and uses about 2048 MBs of PHP memory limit to handle this.

Most LMS sites are built using heavy plugins. A poorly coded plugin or slow-loading theme can impact your site’s performance that results in extensive load time and affect overall user experience. A higher memory limit could help mitigate these problems.

PHP memory limit for a high-traffic multisite:

Current Debate is a top-ranked website on Google for US business news. The readers include local businesses and national franchise brands. A highly visited multisite, Current Debate uses around 16GB of PHP memory at max.

With multisite, one website has access to all the resources. To optimize performance on both the front and back ends, it might need to increase its memory limit.

Conclusion

In general, websites with essentially static content don’t require a large PHP memory limit. 128 – 256 PHP memory limit is a great starting point for bigger websites with more energetic functionality. That said, your memory limit should account for your website’s set of themes, plugins, database queries, and cached-to-uncached proportion.

Share your opinion in the comment section. COMMENT NOW

Share This Article

Customer Review at

“Cloudways hosting has one of the best customer service and hosting speed”

Sanjit C [Website Developer]

Inshal Ali

Inshal is a Content Marketer at Cloudways. With background in computer science, skill of content and a whole lot of creativity, he helps business reach the sky and go beyond through content that speaks the language of their customers. Apart from work, you will see him mostly in some online games or on a football field.

×

Get Our Newsletter
Be the first to get the latest updates and tutorials.

Thankyou for Subscribing Us!

×

Webinar: How to Get 100% Scores on Core Web Vitals

Join Joe Williams & Aleksandar Savkovic on 29th of March, 2021.

Do you like what you read?

Get the Latest Updates

Share Your Feedback

Please insert Content

Thank you for your feedback!

Do you like what you read?

Get the Latest Updates

Share Your Feedback

Please insert Content

Thank you for your feedback!