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

前端之家收集整理的这篇文章主要介绍了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

原文链接:https://www.f2er.com/php/136662.html

猜你在找的PHP相关文章