WordPress Fatal error: Allowed memory size of 5368

2019-02-19 17:53发布

I noticed recently on my WordPress website I'm getting sometimes 500 Internal Server Error. I checked logs and I have many lines like:

[Mon Oct 03 01:25:24.357439 2016] [fcgid:warn] [pid 12840] [client 83.27.211.107:36968] mod_fcgid: stderr: PHP Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 77 bytes) in /var/www/vhosts/mywebsite/public_html/wp-includes/wp-db.php on line 1832

I tried to increase memory limit:

define( 'WP_MAX_MEMORY_LIMIT' , '512M' );

define( 'WP_MEMORY_LIMIT' , '512M' );

And even more, but it didn't work. No matter what I set it still exceeding memory limit by some bytes. I think there's a problem with some queries to a database, but how to check which?

Content of the includes/wp-db.php:

} else {
    $num_rows = 0;
    if ( $this->use_mysqli && $this->result instanceof mysqli_result ) {
        while ( $row = mysqli_fetch_object( $this->result ) ) {
            $this->last_result[$num_rows] = $row;
            $num_rows++;
        }
    } elseif ( is_resource( $this->result ) ) {
        // server crashing at line below
        while ( $row = mysql_fetch_object( $this->result ) ) {
            $this->last_result[$num_rows] = $row;
            $num_rows++;
        }
    }

    // Log number of rows the query returned
    // and return number of rows selected
    $this->num_rows = $num_rows;
    $return_val     = $num_rows;
}

4条回答
一纸荒年 Trace。
2楼-- · 2019-02-19 18:39

Disable the "Database Backups" in iThemes Security works for me.

查看更多
贪生不怕死
3楼-- · 2019-02-19 18:40

The problem was caused by iThemes Security plugin. I turned off it and errors have gone. I'll investigate this problem more and edit this answer if I'll know what part of this plugin caused exceeding memory limit.

查看更多
混吃等死
4楼-- · 2019-02-19 18:42

I had the same issue with "wp-db.php on line 1832" and disabling iThemes Security plugin as was mentioned before worked well for me. However, if you still need to protect your site it's not the solution.

What you need to do is to fix directory permissions of key areas such as wp-content, wp-includes etc...

Go to iThemes Security settings -> File Permissions (Configure Settings) and check if all permissions are set properly. Once you fix permissions as they supposed to be, you won't see that error anymore.

查看更多
Emotional °昔
5楼-- · 2019-02-19 18:50

The constant WP_MEMORY_LIMIT regulates RAM for all PHP processes for WordPress for the front and backends. Use this on shared hosting. The constant WP_MAX_MEMORY_LIMIT regulates RAM for the backend only. You use WP_MAX_MEMORY_LIMIT when you know you have enough RAM and can use it all, such as on a VPS server you administer.

Go back to

define( 'WP_MAX_MEMORY_LIMIT' , '128M' ); define( 'WP_MEMORY_LIMIT' , '64M' );

and remove those queries you are running (above) and see if the site comes back up. If it does, that's the issue; working on those queries is a different issue.

If this is shared hosting, you are killing the server with those queries; if this is your own server, you need to configure MySQL/PHP for caching and high loads.

查看更多
登录 后发表回答