php – 允许的内存大小为134217728字节耗尽(尝试分配4294967296字节)

我的项目使用开源 PHP MysqLhttps://github.com/ajillion/PHP-MySQLi-Database-Class

但该项目年中报告:“致命错误:允许内存大小为134217728字节耗尽(试图分配4294967296字节)在/ home1 / flipalbu / public_html / kvisofttest / login-admin / Lib / class.MysqLiDb.PHP第422行“这个错误,

我的服务器是:linux x86_64

PHP版本5.4.17

MysqL版本:5.5.32

memory_limit = 128M

第422行:call_user_func_array(array($stmt,’bind_result’),$parameters);

查询部分代码

$db = new MysqLiDb ('LocalHost','root','PASSWD','DB');
$wqdb = $db-> query ("SELECT * FROM db_table");
foreach ($wqdb as $row) {
 $con. = $row ['ID'];
}
echo $con;

有什么办法可以解决吗?

/** 错误代码 **/

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 as $key => $val) {
                    $x[$key] = $val;
                }
                array_push($results,$x);
            }
            return $results;
        }
在这里阅读了这个错误报告: https://bugs.php.net/bug.php?id=51386

你的问题似乎发生了,因为表格的列中有一个longblob或longtext.

longtext / longblob的最大长度为4294967295 [4GB],这就是MysqLi尝试为缓冲区分配内存以确保没有丢失的原因.我建议您使用mediumtext(16777215 [16MB]最大长度),这应该足够通常.

更新:
因为这个答案已经看到一些活动我从Phil_1984添加了这个解决方案(见评论)

I use MysqLi and after reading that quote from PHP dev,adding a
$stmt->store_result(); between execute and bind_result seems to fix
the issues for me

=>如果你使用$stmt-> store_result(),你可以使用MysqLi和longblob / longtext而不会收到错误.

旧答案:
我建议您将列更改为另一种类型(mediumtext)或使用PDO(我认为它没有这个问题).但是如果你想把列保留为longtext,你必须切换你的MysqL

引自PHP Dev:

This is a kNown limitation of ext/MysqLi when using libMysqL (always in 5.2 and prevIoUs) and when libMysqL is enabled with 5.3 . The reason is that the server sends not too specific Metadata about the column. This longtext has a max length of 4G and ext/MysqLi tries to bind with the max length,to be sure no data loss occurs (data doesn’t fit in the bind buffer on C level). However,that means 4G for a longtext/longblob column. ext/MysqLi has been changed to have a way to work around that. You need to call MysqLi_stmt_store_result() which will store the data locally,which means,of course a higher memory usage for PHP. However,because you use libMysqL this won’t hit the PHP’s memory limit,for sure. During store_result the max_length of every column will be calculated and then when bind_result is executed only a buffer with size of max_length will be allocated,which will be definitely lower than 4G. In short,prepare execute store_result bind_result fetch…fetch…fetch

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...