php - Allowed memory size of 134217728 bytes exhausted (tried to allocate 4294967296 bytes) -
my project uses open source php mysql library https://github.com/ajillion/php-mysqli-database-class
but project mid-year report: "fatal error: allowed memory size of 134217728 bytes exhausted (tried allocate 4294967296 bytes) in / home1/flipalbu/public_html/kvisofttest/login-admin/lib/class.mysqlidb.php on line 422" error ,
my server is: linux x86_64
php version 5.4.17
mysql version: 5.5.32
memory_limit = 128m
line 422:call_user_func_array (array ($ stmt, 'bind_result'), $ parameters);
query part of code:
$ db = new mysqlidb ('localhost', 'root', 'passwd', 'db'); $ wqdb = $ db-> query ("select * db_table"); foreach ($ wqdb $ row) { $ con. = $ row ['id']; } echo $ con; is there way solve it?
/** error code **/
protected function _dynamicbindresults(mysqli_stmt $stmt) { $parameters = array(); $results = array(); $meta = $stmt->result_metadata(); $row = array(); while ($field = $meta->fetch_field()) { $row[$field->name] = null; $parameters[] = & $row[$field->name]; } call_user_func_array(array($stmt, 'bind_result'), $parameters); while ($stmt->fetch()) { $x = array(); foreach ($row $key => $val) { $x[$key] = $val; } array_push($results, $x); } return $results; }
i read bug report here: https://bugs.php.net/bug.php?id=51386
your problem seems happen because there longblob or longtext in columns of table.
longtext / longblob have maximum length of 4294967295 [4gb] thats why mysqli tries allocated memory buffer sure nothing lost. suggest use mediumtext (16777215 [16mb] max length), should enough usually.
update: because answer has seen activity add solution phil_1984 (see comments)
i use mysqli , after reading quote php dev, adding $stmt->store_result(); between execute , bind_result seems fix issues me
=> if use $stmt->store_result() can use mysqli longblob / longtext without getting error.
-
old answer: suggest either change column type (mediumtext) or use pdo (i think doesnt have problem). if want keep column longtext, have switch mysql library
quote php dev:
this known limitation of ext/mysqli when using libmysql (always in 5.2 , previous) , when libmysql enabled 5.3 . reason server sends not specific metadata column. longtext has max length of 4g , ext/mysqli tries bind max length, sure no data loss occurs (data doesn't fit in bind buffer on c level). however, means 4g longtext/longblob column. ext/mysqli has been changed have way work around that. need call mysqli_stmt_store_result() store data locally, means, of course higher memory usage php. however, because use libmysql won't hit php's memory limit, sure. during store_result max_length of every column calculated , when bind_result executed buffer size of max_length allocated, lower 4g. in short, prepare execute store_result bind_result fetch...fetch...fetch
Comments
Post a Comment