• Resolved linux4me2

    (@linux4me2)


    I noticed that on a number of sites I manage, the error_log in /wp-admin is filling up with PHP warnings like these:

    [18-May-2023 16:23:14 UTC] PHP Warning:  Constant WP_MEMORY_LIMIT already defined in /home/username/domain.com/wp-config.php on line 100
    [19-May-2023 16:23:10 UTC] PHP Warning:  Constant WP_MEMORY_LIMIT already defined in /home/username/domain.com/wp-config.php on line 100

    Once a day, every day, same time, which makes it look like a cron-related thing.

    The sites do all have the WP_MEMORY_LIMIT constant defined in wp-config.php in order to increase the memory limit. I haven’t been able to tell where–other than in wp-config.php–WordPress is trying to re-define WP_MEMORY_LIMIT to cause the warning.

    So I set up a test site with no plugins and used the default Twenty Twenty Two theme.

    The warnings continue, so it seems like it’s got to be coming from WordPress itself.

    I SSH’d into the server and from the root folder, ran the following:

    grep -r 'WP_MEMORY_LIMIT' .

    The only relevant result was in /wp-includes/default-constants.php, but it’s contained within a conditional block that fires the code only if WP_MEMORY_LIMIT is not already defined, so that doesn’t appear to be the culprit.

    Is anybody else getting these warnings or know how to fix them?

Viewing 11 replies - 1 through 11 (of 11 total)
  • Moderator t-p

    (@t-p)

    on line 100 of wp-config.php? That’s like at the end of the file, right?
    If so, try moving it before the following line:

    /* That's all, stop editing! Happy blogging. */

    Thread Starter linux4me2

    (@linux4me2)

    Hi @t-p,

    Not the end of the file in my wp-config.php, it’s on lines 99 and 100:

    // Increase the WP Memory Limit.
    define('WP_MEMORY_LIMIT', '256M');
    
    /* That's all, stop editing! Happy publishing. */

    And it’s the only declaration for WP_MEMORY_LIMIT in wp-config.php. That’s the first thing I checked. : )

    Moderator t-p

    (@t-p)

    So I set up a test site with no plugins and used the default Twenty Twenty Two theme.

    Check that theme’s functions.php in case someone put it there.

    Thread Starter linux4me2

    (@linux4me2)

    It was using a Twenty Twenty Two child theme, but there was nothing in the functions.php that related to WP_MEMORY_LIMIT, just some code to use SMTP mail and enqueuing the parent theme’s and child theme’s style sheets.

    However, just to be sure, I switched it to the default Twenty Twenty Two theme using an untouched functions.php, and I’m going to check tomorrow to see if the warning recurs.

    Moderator t-p

    (@t-p)

    Okay. If the issue persists, you may also want to discuss this with your hosting provider.

    Thread Starter linux4me2

    (@linux4me2)

    Hi @t-p

    What hosting-related issue are you thinking may be involved?

    Moderator t-p

    (@t-p)

    What hosting-related issue are you thinking may be involved?

    That’s what, if any, you ask your hosting provider.

    Thread Starter linux4me2

    (@linux4me2)

    Oh, I thought you had something in mind. I have a good host, and I’m sure they’ll make an effort, but I can’t imagine they will be helpful in this case. Still, it’s worth a try. If I still see the warning with the plain-vanilla default theme, I’ll see what they say.

    Thread Starter linux4me2

    (@linux4me2)

    I confirmed that it is not the child theme, as the warnings still occur like clockwork with a plain-vanilla default theme.

    Thread Starter linux4me2

    (@linux4me2)

    I believe the problem is that I was led down a rabbit hole when I really just need to remove the WP_MEMORY_LIMIT declaration from my wp-config.php to resolve the warnings in my error log.

    Without the WP_MEMORY_LIMIT declaration, one of the plugins I was using was giving me a warning that WP_MEMORY_LIMIT was only 40 MB. I interpreted that to mean that I didn’t have enough memory allocated to WordPress, even though my server’s PHP memory limit is set to 256 MB.

    However, when I looked at the code in /wp-includes/default-constants.php that handles WordPress’ memory allocation, it’s clear that WordPress only tries to set the PHP memory limit when WP_MEMORY_LIMIT is greater than the PHP memory limit. If it’s the same, as in my case, there is no need to set WP_MEMORY_LIMIT in wp-config.php.

    According to WordPress’ wp-config.php documentation:

    if PHP has been allocated 64MB, there is no need to set this value to 64M as WordPress will automatically use all 64MB if need be.

    Substitute “256” for “64”, and that’s exactly my situation.

    I’m going to remove the wp-config.php WP_MEMORY_LIMIT declaration, which should fix the “problem.”

    Moderator t-p

    (@t-p)

    Glad its sorted ??

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘PHP Warning: Constant WP_MEMORY_LIMIT Already Defined In wp-config.php’ is closed to new replies.