• I have a WP installation hosted with cPanel. In cPanel I am setting the php memory_limit to 3G. Checking the Tools > Site Health > Info > Server > PHP Memory Limit setting it reads 3G. Then I go back to cPanel php.ini configuration and I set the memory limit to 128M. Refreshing the WP appropriate page it now reads 256M. I have checked the .htaccess file and the same directives as set in the php.ini file are present there. I checked the wp-config.php file next, and there were no relevant constants set there at all.

    I then returned to the WP page, and this time I checked the WordPress Constants drop down, and there I noticed the presence of the WP_MEMORY_LIMIT and WP_MAX_MEMORY_LIMIT options. They were reading 80M and 256M accordingly. That hinted me perhaps I should define both in wp-config, which I did, and I set both to 128M. Refreshing the page of WP’s I can see that under the WordPress Constants drop-down section both WP_MEMORY_LIMIT and WP_MAX_MEMORY_LIMIT are set to 128M, but under Server the PHP Memory Limit remains to 256M still.

    That is hinting me that perhaps the wp-config settings have nothing to do with the PHP Memory Limit after all. Is that assumption correct? Had it anything to do with PHP Memory Limit, I should be seeing a PHP Memory Limit of 128M after having changed all three settings to 128M. Where else should I be looking into on the server’s end? Lastly, if what is applying the memory limit to 256M is overriding the php.ini’s setting, shouldn’t that be the case when the php.ini setting is set at 3G also?

    What is it that I have been missing? Please advise.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Hi @skredlemon

    The WP_MEMORY_LIMIT and WP_MAX_MEMORY_LIMIT constants will only take affect on the WordPress instance, and will be limited to what is set as the memory limit for PHP, which you are setting in the cPanel settings.

    I’m not sure why when you set the cPanel php.ini memory limit from 3GB to 128M, but it then shows as 256M.

    It is possible to have multiple php.ini files though, so one might be overriding the other. You might need to check with your hosting provider if there are multiple php.ini files that could be setting the PHP memory limit.

    Once way you can check to see what ini files are being loaded is to create a phpinfo.php file in the root of your WordPress install, use the phpinfo function, and then browse to that file. This will give you a bunch of information about the php.ini files being loaded, as well as the values that have been configured for PHP

    https://www.php.net/manual/en/function.phpinfo.php

    Moderator bcworkz

    (@bcworkz)

    WP memory limits are normally set in wp_initial_constants(). Check the source code. It is only set if server configuration allows PHP to alter the value with ini_set(). But only if the constants have not already been defined earlier, such as in wp-config.php.

    Setting the constants in wp-config.php should override the WP values. Apparently how you did so is in error somehow. Maybe also defined elsewhere in the file, causing your code to be ignored? PHP may not log a warning for redefined constants, it just ignores subsequent definitions.

    It’s possible to set WP constants greater than the php.ini value. If the WP value so set is not more than what’s physically available, it’s probably OK, but seems like a bad idea to contradict php.ini. I also don’t know what purpose a WP_MAX_MEMORY_LIMIT is for if the WP_MEMORY_LIMIT value is what is used. In any case, these constants can only be defined once.

    Thread Starter Konstatninos

    (@skredlemon)

    @bcworkz I checked that file, and it all seems normal comparing to the link you shared. I quote:

    $current_limit     = ini_get( 'memory_limit' );
    	$current_limit_int = wp_convert_hr_to_bytes( $current_limit );
    
    	// Define memory limits.
    	if ( ! defined( 'WP_MEMORY_LIMIT' ) ) {
    		if ( false === wp_is_ini_value_changeable( 'memory_limit' ) ) {
    			define( 'WP_MEMORY_LIMIT', $current_limit );
    		} elseif ( is_multisite() ) {
    			define( 'WP_MEMORY_LIMIT', '64M' );
    		} else {
    			define( 'WP_MEMORY_LIMIT', '40M' );
    		}
    	}
    
    	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' );
    		}
    	}

    @psykro I checked phpinfo and the only helpful data in there in this case is the following confirmation. Other than that no multiple php.ini files exist, and the /opt/cpanel/ea-php74/root/etc/php.ini master configuration file defines the same limit, which is being ignored. (i.e. 128M).

    https://ibb.co/hLygg0b

    @skredlemon I know you mentioned that your site is hosted with cPanel. cPanel is web hosting software, typically installed on a server by a web host. Do you have a web host company that you are paying for your web hosting, or is this a server you manage yourself?

    @skredlemon I just did a check online, and master value is what is set in the php ini file, and the local value is what would be set either in .htaccess, or another Apache related configuration file.

    https://www.a2hosting.co.za/kb/developer-corner/php/using-php-directives-in-custom-htaccess-files/setting-the-php-script-memory-limit-in-an-htaccess-file

    https://stackoverflow.com/questions/19520744/what-is-the-difference-between-local-value-and-master-value

    You mentioned earlier that you checked your .htaccess file, and the same values are set, perhaps it is set in another Apache related configuration file?

    Thread Starter Konstatninos

    (@skredlemon)

    It is a server I manage myself. Instead of Apache, the server software in use is actually Litespeed, which is also making use of .htaccess files. I’ve checked everything I could think of, but haven’t discovered any configuration file responsible for this behavior. Whenever I edit the php.ini settings in cPanel, the changes take effect in .htaccess immediately. It’s good to know that we have checked – and ruled out – all wp-related places responsible for this. Perhaps we’re getting somewhere.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘What else could be controlling my Server’s PHP Memory Limit?’ is closed to new replies.