-2

I have a problem that drives me nuts for some time, and can't find a solution to it :-(
From time-to-time I get this error message on our wordpress/woocommerce site Fatal error: Allowed memory size of 201326592 bytes exhausted (tried to allocate 1048576 bytes) in xxxxx/wp-includes/wp-db.php on line 1842 After refresh, the page loads regularly.

I checked the referenced lines in wp-db.php, and it is this code:

$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++;
        }

While searching the net, I found some tips for solution, like checking MySQLi, enlarging php memory, optimising database (deleting orphaned post-meta and WPs Automatic Database Optimizing), but none of them worked. The host says the memory is not any problem with the load of the server, but it is some coding issue.
Any idea how I can find the problem that needs fixing?
I tried the ini_set('memory_limit', '-1'); hack to make the php memory infinite (I know it is not a good practise), but it didn't help.
Any idea how this issue can be traced down, which code makes the mess?

Gas
  • 727
  • 2
  • 12
  • 32
  • Sometimes these sorts of error messages can trip you up. Although PHP is referencing a line in `wp-db.php` that's not where the actual issue is. – Nathan Dawson Feb 04 '17 at 12:36
  • Possible duplicate of [Allowed memory size of 33554432 bytes exhausted (tried to allocate 43148176 bytes) in php](http://stackoverflow.com/questions/415801/allowed-memory-size-of-33554432-bytes-exhausted-tried-to-allocate-43148176-byte) – Manoj Sharma Feb 04 '17 at 12:41
  • I tried the ini_set('memory_limit', '-1'); as suggested in the other post, but it didn't help me :-( – Gas Feb 04 '17 at 13:44
  • So, basically then I have some infinite loop somewhere that eats up the memory? How can I check it where, is there some php troubleshooter, or logger for this? – Gas Feb 04 '17 at 14:19

1 Answers1

-1

Try to use the function mysqli_result::fetch_all

and iterate result yourself, to avoid inifinite loop ... that can be solved your problem may be ^^

if ( $this->use_mysqli && $this->result instanceof mysqli_result ) {
  $results = mysqli_fetch_all($this->result);
  foreach($result as $r) {
    //do stuff
  }
}
Stev tuned
  • 65
  • 4
  • Thanks, but should I really change wordpress' wp-db.php? Isn't it unwise in terms of functionality and updates? Or should I rewrite the function in functions.php? – Gas Feb 04 '17 at 10:43
  • @Gas Absolutely not! Neither is appropriate. The problem isn't with `wp-db.php` or any line within that file. – Nathan Dawson Feb 04 '17 at 12:34