3

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;
}
7
  • so ask yourself WHY you need to cache 500+megs of data in ram. If you HAVE to, then your choices are to either raise/remove the memory limit, or rebuild your system so you DON'T need that much stuff in memory at the same time. Otherwise you're basically asking "I poured 10 liters of water into a 1 liter bucket and it overflowed, how can I keep it form overflowing?" Commented Oct 3, 2016 at 21:19
  • Your own server or a webhost? Commented Oct 3, 2016 at 21:27
  • @MarcB, you don't understand. I have a bug on my website. It's simple WordPress site with 5 widgets, menu and posts loop (20 per page). I don't have an idea why this exceeding memory limit at all. Commented Oct 3, 2016 at 21:29
  • @markratledge No, I have only access to files via FTP. Commented Oct 3, 2016 at 21:30
  • well, then do some basic debugging: take a look at what the query is, and run it yourself to see what data it's bringing back. there's nothing "simple" about wordpress. it is a bloated pig of a system, frankly, and even a "simple" page will be a hefty burden on the system. Commented Oct 3, 2016 at 21:31

4 Answers 4

1

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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.

1 Comment

It is the "Database Backups" of iThemes Security that causes OOM. Purely disable that function should be fine.
1

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

Comments

0

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.

4 Comments

Seems to me he is copy/pasting the core WP file. I would be surprised if that turned out to be the culprit.
I edited my post. I forgot to mention that part of a code I posted is from wp-incudes/wp-db.php. So, I don't know where is a query that caused this bug. Maybe it's from a plugin, that website worked properly a few weeks ago.
@RST, yes, I forgot to mention that. Sorry.
Talk to your host; many shared hosts do not provide enough RAM. If this is a brand new site and new problem on a new hosting account, the host is the problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.