define( 'WP_MEMORY_LIMIT', '-1' );

define( 'WP_MAX_MEMORY_LIMIT', '-1' );

So have a quite big server, I wish any of the websites to use maximum available ram.

Will these settings work or will I have to define a positive max value?

  • The question I have is why do you need to have unlimited memory? But I would set it to the server's memory minus 32/64/128. – Cedon Mar 22 '18 at 1:11
  • @cedon If there's 128GB with only a bunch of medium-sized wp sites, you will think of making the most of the server. So as we have to configure the file while is in php will the above lines work ? – Ashish Dung Dung Mar 22 '18 at 1:28

If you search WP source code, you'll find _MEMORY_LIMIT in wp-includes/default-constants.php

$current_limit     = @ini_get( 'memory_limit' );
$current_limit_int = wp_convert_hr_to_bytes( $current_limit );
if ( ! defined( 'WP_MAX_MEMORY_LIMIT' ) ) {
    if ( false === wp_is_ini_value_changeable( 'memory_limit' ) ) {
        define( 'WP_MAX_MEMORY_LIMIT', $current_limit );
    } elseif ( -1 === $current_limit_int || $current_limit_int > 268435456 /* = 256M */ ) {
        define( 'WP_MAX_MEMORY_LIMIT', $current_limit );
    } else {
        define( 'WP_MAX_MEMORY_LIMIT', '256M' );

That second conditional says make WP_MAX_MEMORY_LIMIT be -1 if your server is set to -1.

So I'd say, yeah, it'll work. Give'r. Do note though that $current_limit (the -1 they've used) might be an integer, not a string. I'm not sure if that matters. From php.net

ini_get() will return the exact string stored in the php.ini file and NOT its integer equivalent. Attempting normal arithmetic functions on these values will not have otherwise expected results. The example above shows one way to convert shorthand notation into bytes, much like how the PHP source does it.

Redardless, I'd never do it. If you have a bad script doing somthing silly like an infinite loop, you could have some weird things happen, and 128gb can get eaten quicker than you think. You'd want the script to break and preserve your server, instead of clogging and maxing it out. Especially when you have multiple sites sharing the resources. If you have any php script in WP that needs more than >256mb, that's ridiculous.

again from php.net:

memory_limit integer This sets the maximum amount of memory in bytes that a script is allowed to allocate. This helps prevent poorly written scripts for eating up all available memory on a server. Note that to have no memory limit, set this directive to -1.

When an integer is used, the value is measured in bytes. Shorthand notation, as described in this FAQ, may also be used.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.