微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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.jb51.cc/php/136662.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐