What is the PHP memory_limit?

Austin B.
Published: 21 June 2021
Share:

The PHP memory_limit is the maximum amount of server memory that each PHP script can use. 

The official PHP documentation explains this in greater detail. 

“This sets the maximum amount of memory in bytes that a script is allowed to allocate. This helps prevent poorly written scripts from eating up all available memory on a server.”  

PHP memory usage is typically managed by the PHP interpreter and the web server running PHP scripts. PHP has a default memory limit setting, which restricts the amount of memory a script can use.  

The default value for PHP memory is 128M. This can be raised if an application or website needs more memory. 

It's important to note that allocating too much memory to PHP can also have negative consequences, such as slowing down the application or causing other performance issues. This may be due to a specific PHP process using far too much memory than what is available. 

When a script exceeds the memory limit that's been set for the server an error similiar to the following will be logged.

Fatal error: Allowed memory size of x bytes exhausted (tried to allocate x bytes) in /example/php/script PHP Fatal error: Out of memory (allocated x) (tried to allocate x bytes) in /example/php/script

You can update the PHP memory limit for your site through My20i or StackCP.