Php ini max memory

Important: Shared hosting accounts are limited to no more than 64M, even if the limit is set to be higher inside of the php.ini file. VPS or Dedicated hosting services can set the limit to match their RAM. To help your website run at maximum performance, it is optimal for the memory limit to be set as low as possible while still allowing your website to function.

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 should be the memory limit in PHP ini?

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.

How do I check my PHP memory limit?

Show activity on this post..
PHP-CLI: Command line to check ini: $ php -r "echo ini_get('memory_limit');" Or check php-cli info and grep memory_limit value: $ php -i | grep "memory_limit".
PHP-FPM: Paste this line into index.php or any php file that can be viewed on a browser, then check the result: <?.

How do I set PHP

For example, to increase the PHP memory limit:.
Edit the main PHP configuration file at /opt/bitnami/php/etc/php.ini and set the memory_limit variable to a new value, as shown below: memory_limit=NEW_LIMIT..
Modify the PHP-FPM pool configuration file and set the corresponding variable as follows..

How do I increase my server memory limit?

ini file on your server, please follow this steps :.
Open the php. ini file..
Search for the following text : β€œmemory_limit”.
Increase this value to 64MB as shown bellow :.