Change memory limit php ini

PHP has a memory limit configuration that determines the maximum amount of memory a single PHP script can consume.

This memory_limit is usually defined in a php.ini file as follows:

memory_limit = 128M

The default memory_limit configuration for PHP is 128M or 128 Megabytes. You can replace this value in your php.ini file with any other

; πŸ‘‡ limit to 256 Megabytes
memory_limit = 256000000

; πŸ‘‡ this is the same
memory_limit = 256M
1 value.

Without the

; πŸ‘‡ limit to 256 Megabytes
memory_limit = 256000000

; πŸ‘‡ this is the same
memory_limit = 256M
2 symbol, the limit will be measured in bytes:

; πŸ‘‡ limit to 256 Megabytes
memory_limit = 256000000

; πŸ‘‡ this is the same
memory_limit = 256M

The memory limit in PHP is calculated on a pre-script basis, meaning that each PHP script request is independent of the other.

For example, if you have 3 running PHP scripts where each consumes 90MB of memory, then the total memory used by PHP will be 270MB passing the 128MB limit.

When you have a single PHP script that consumes 200MB of memory, then PHP will throw an

; πŸ‘‡ limit to 256 Megabytes
memory_limit = 256000000

; πŸ‘‡ this is the same
memory_limit = 256M
3 fatal error.

To remove the memory_limit, you can set the value as

; πŸ‘‡ limit to 256 Megabytes
memory_limit = 256000000

; πŸ‘‡ this is the same
memory_limit = 256M
5 like this:

memory_limit = -1

This way, PHP won’t have memory limitations and can consume all available memory on your server.

Aside from editing the php.ini file, you can also edit the

; πŸ‘‡ limit to 256 Megabytes
memory_limit = 256000000

; πŸ‘‡ this is the same
memory_limit = 256M
7 file as shown below:

php_value memory_limit 256M

You can get the current memory_limit value with the

; πŸ‘‡ limit to 256 Megabytes
memory_limit = 256000000

; πŸ‘‡ this is the same
memory_limit = 256M
9 function:

echo ini_get("memory_limit"); //128M

You can also change the memory limit configuration only for a specific script using

memory_limit = -1
0 function:

// πŸ‘‡ set memory limit as 256M using ini_set()

echo ini_set("memory_limit", "256M");

And that’s how you set the memory_limit configuration in PHP.

If you’re using editing the memory_limit for a WordPress site, keep in mind that WordPress has its own memory constants defined as:

  • memory_limit = -1
    
    3 sets the memory limit in WP frontend area
  • memory_limit = -1
    
    4 sets the memory limit in WP administration area

The

memory_limit = -1
3 is usually set at 64MB for WP multisite and 40MB for a single site, while
memory_limit = -1
4 is usually set at 256MB.

You can define these constants in

memory_limit = -1
7 file, below the
memory_limit = -1
8 definition as shown below:

define( 'WP_DEBUG', true );

/* Add any custom values between this line and the "stop editing" line. */
define( 'WP_MEMORY_LIMIT', '300M' );
define( 'WP_MAX_MEMORY_LIMIT', '300M' );

WordPress configuration doesn’t override the PHP configuration, so make sure you have memory_limit at 300MB or more when you set

memory_limit = -1
3 and
memory_limit = -1
4 at 300MB.

What is the max memory limit for PHP?

The default memory limit is 256M and this is usually more than sufficient for most needs. If you need to raise this limit, you must create a phprc file.

How do I increase PHP INI memory limit in cPanel?

How to increase the PHP Memory Limit in cPanel.
1) Log into cPanel..
2) Look for the SOFTWARE section and click on Select PHP version..
3) In the new window click on the Switch To PHP Options button..
4) Here you can locate the memory_limit and click on the value..

How do I increase memory limit in WP

Edit your wp-config. Open the wp-config. php file and search for this text string: define('WP_MEMORY_LIMIT', '32M'); Then, modify it to read define('WP_MEMORY_LIMIT', '128M'); You can go as high as 256MB, but in most cases, you won't need this much memory.

How to reduce memory usage in PHP?

PHP Memory Usage and Performance Improvements Tips.
Use objects with declared properties over array..
Be careful to self-referencing that would prevent garbage collector from work..
PHP Benchmarking..
PHP benchmarks and optimizations..