Make WordPress Core

Opened 4 years ago

Last modified 4 years ago

#52143 new enhancement

memory_limit not always adhered

Reported by: danielbareman's profile danielbareman Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 5.6
Component: General Keywords: reporter-feedback
Focuses: performance Cc:

Description

From time to time I notice that WordPress, or it's plugin don't adhere the "memory_limit" that's set by it's php.ini or through .htaccess

A simple and quick fix, is adding the following line:

define('WP_MEMORY_LIMIT', ini_get('memory_limit'));

I'd suggest adding this line to the default contents of wp-config.php to resolve the issue in the cases it occurs.

Change History (3)

This ticket was mentioned in Slack in #core by lukecarbis. View the logs.


4 years ago

#2 @kirasong
4 years ago

  • Keywords reporter-feedback added

Hi @danielbareman!

Thanks for opening the ticket.

The intent behind the define, so I understand it, is to provide reasonable defaults / expectations for PHP memory, and raise that value when appropriate.

Here's the start of the relevant code:
https://github.com/WordPress/wordpress-develop/blob/029dd1bbb929eec4df5f57789ef42c076aab83f0/src/wp-includes/default-constants.php#L37

It looks like when it is not able to be changed by WordPress, the behavior is as you suggest:
https://github.com/WordPress/wordpress-develop/blob/029dd1bbb929eec4df5f57789ef42c076aab83f0/src/wp-includes/default-constants.php#L43

It sounds like maybe you're looking for WordPress to keep itself and plugins from going over a certain amount of memory, or am I mistaken? Could you please explain a bit more the symptoms of the issue you're having? Would be interested in understanding the use-case.

Thanks again!

#3 @danielbareman
4 years ago

Hello @mikeschroder

First of all, thanks for you're reply and looking into this.

The reason behind my suggestion is that I work at a technical help desk of a dutch hosting company.

We get some customers asking if they can get their memory increased as it only shows 40Mb, which means it defaults to when the other if's don't succeed: https://github.com/WordPress/wordpress-develop/blob/029dd1bbb929eec4df5f57789ef42c076aab83f0/src/wp-includes/default-constants.php#L47

So initially it seems the line below doesn't work out.

if ( false === wp_is_ini_value_changeable( 'memory_limit' ) )

Which could be a specific thing caused by our hosting envoirement?
I've just now looked into https://developer.wordpress.org/reference/functions/wp_is_ini_value_changeable/ and did a test with "ini_get_all" which defaults in:

Array
(
    [global_value] => 128M
    [local_value] => 128M
    [access] => 7
)

Or with "php_value memory_limit 256M" in a ".htaccess"

Array
(
    [global_value] => 128M
    [local_value] => 256M
    [access] => 7
)

At least, after contact of a customer and by adding te line below to their "wp-config.php" it resolves and sets it to the value that's assigned by php.ini or altered with the help of a '.htaccess'.

define('WP_MEMORY_LIMIT', ini_get('memory_limit'));
Note: See TracTickets for help on using tickets.