PHP-MySQLi-Database-Class icon indicating copy to clipboard operation
PHP-MySQLi-Database-Class copied to clipboard

Allowed memory size of 134217728 bytes exhausted (tried to allocate 4294967320 bytes)

Open pisgo opened this issue 6 years ago • 5 comments

Hello everyone ~ I would like help.

$ sg_rst = $ db_slave-> rawQueryOne ("CALL SP_ADMIN_GET_USER_LOGIN ('id', 'pw')");

I am getting the following error when requesting.

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 4294967320 bytes) in /class/MysqliDb.php on line 1631

The code for the error location is shown below. In _dynamicBindResults () the following code while ($ field = $ meta-> fetch_field ()) {

As follows Without a procedure, a normal query is processed normally without memory problems.

$sql = " SELECT 1 AS code, 'success' AS msg, user_idx, user_email, user_name, user_tel, user_photo, user_state, user_type FROM T_USER WHERE user_id = 'tstestqa01'; ";

$sg_rst = $db_slave->rawQueryOne ($sql);

Development environment information is as follows. PHP 7.0.33 MYSQL 5.6.10 MysqliDb Class 2.9-master

The general query is processed normally, but the procedure call is error only.

Thank you for your help.

pisgo avatar Mar 06 '19 08:03 pisgo

Same problem with this simple


$links = link::where('lastView', null, 'IS NOT')
                ->get(50000);
echo 'hello';
var_dump($links);
print_r($links);
die('here');

"hello" is not printing... and script stop before with page blank but 200 status code, my php-error.log PHP Fatal error: Allowed memory size of 2097152 bytes exhausted (tried to allocate 20480 bytes) in ..... vendor/thingengineer/mysqli-database-class/MysqliDb.php on line 1669

and my user.ini is:


memory_limit = 1GB
display_errors = On
display_startup_errors = On
html_errors = 1
error_reporting = 32767
log_errors = 1
error_log = "/.............logs/phperrors.log"

I also try ini_set("memory_limit","20GB"); ...not work

Question is, because not work? because error are not displayed but logged in right place? 20GB ram isn't sufficient or ur class decrese this limit in someplace ?

thanks.

KTP95 avatar Apr 17 '20 06:04 KTP95

I have the same problem, the works works in my local environment... I have a server with more ram memory capacity, the same configurations.

But on my server (already tried with apache2 and xampp) I keep getting the same error.

I already increased all the memory values

rockdrc avatar Jan 15 '22 16:01 rockdrc

Hi @rockdrc.

I'm currently facing this issue with the same symptoms. Everything is fine on my local environment, and when I deploy to prod server the memory consumption is drastically exploding...

I tried a lot of unsuccessful solutions picked elsewhere... Do you have a clue 3 years later?

davvalent avatar May 03 '22 04:05 davvalent

@davvalent Good morning.

Yes, I managed to fix it...

I still have a deep understanding of what exactly is going on.

  1. You can use Example # 1 Executing a prepared statement with named substitution parameters

https://www.php.net/manual/en/pdostatement.bindvalue.php

  1. Try all string strings, use TRIM, to remove all spaces, I used to get strings with special characters and that generated the error.

Good luck! .

rockdrc avatar May 03 '22 13:05 rockdrc

Thank you @rockdrc, very appreciated.

Based on your input and some clues I've got elsewhere it looks like it's a problem between the database configuration and PHP-MySQLi-Database-Class.

This is how I solved this problem:

Step 1

I found these lines in mysqli-database-class/MysqliDb.php (v2.9.3), in the _dynamicBindResults() method:

// avoid out of memory bug in php 5.2 and 5.3. Mysqli allocates lot of memory for long*
// and blob* types. So to avoid out of memory issues store_result is used
// https://github.com/joshcam/PHP-MySQLi-Database-Class/pull/119
if ($shouldStoreResult) {
    $stmt->store_result();
}

My prod server is running PHP 7.4.28, so it's a fix from an old bug... But let's give a try.

So I switched $shouldStoreResult from false to true. Good news, this is a very good improvement since the error is gone: the memory peak decreased from from 2.5GB (!) to 2.88MB (!!!).

But the output of the script became buggy, I don't know why (I send back JSON content to client).

Step 2

I found the only notable difference between my local dev environment and the prod server is the database collation.

  1. I dropped all tables of the database
  2. I switched the database collation from latin1_swedish_ci to utf8mb4_general_ci
  3. I loaded back the data

Now everything is operating smoothly.

davvalent avatar May 03 '22 18:05 davvalent