耗尽的允许内存大小为134217728字节(尝试分配4294967296字节) [英] Allowed memory size of 134217728 bytes exhausted (tried to allocate 4294967296 bytes)

查看:527
本文介绍了耗尽的允许内存大小为134217728字节(尝试分配4294967296字节)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

My project uses an open source PHP MySQL library https://github.com/ajillion/PHP-MySQLi-Database-Class

但是该项目的年中报告:致命错误:/home1/flipalbu/public_html/kvisofttest/login-admin/Lib/class.MysqliDb.php中的134217728字节的已用尽内存大小(尝试分配4294967296字节)在第422行上",此错误,

But the project mid-year report: "Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 4294967296 bytes) in / home1/flipalbu/public_html/kvisofttest/login-admin/Lib/class.MysqliDb.php on line 422" This error ,

我的服务器是:linux x86_64

My server is: linux x86_64

PHP版本5.4.17

PHP Version 5.4.17

Mysql版本:5.5.32

Mysql Version: 5.5.32

memory_limit = 128M

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;
        }

推荐答案

我在这里阅读了此错误报告:

I read this bug report here: https://bugs.php.net/bug.php?id=51386

您的问题似乎发生了,因为表的列中有longbloblongtext.

Your problem seems to happen because there is a longblob or longtext in the columns of the table.

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

longtext / longblob have a maximum length of 4294967295 [4GB] thats why mysqli tries to allocated that memory for the buffer to be sure nothing is lost. I would suggest that you use mediumtext (16777215 [16MB] max length), that should be enough for everything usually.

更新: 因为这个答案看到了一些活动,所以我在Phil_1984中添加了此解决方案(请参阅评论)

Update: Because this answer has seen some activity I add this solution from Phil_1984 (see comments)

我使用mysqli,并在阅读了php dev的引用后,添加了 $ stmt-> store_result();执行和bind_result之间似乎已修复 给我的问题

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一起使用,而不会出现错误.

=> If you use $stmt->store_result() you can use mysqli with longblob / longtext without getting the error.

-

旧答案: 我建议您将列更改为另一种类型(中文本)或使用PDO(我认为它不存在该问题).但是如果您想将该列保留为长文本,则必须切换mysql库

Old Answer: I suggest that you either change the column to another type (mediumtext) or use PDO (i think it doesnt have that problem). but if you want to keep the column as longtext, you have to switch your mysql library

PHP Dev的报价:

Quote from PHP Dev:

这是使用libmysql时ext/mysqli的已知限制(总是 (在5.2及更低版本中)和libmysql在5.3中启用.这 原因是服务器发送的关于以下内容的元数据不太具体: 柱子.该长文本的最大长度为4G,并且ext/mysqli尝试 绑定最大长度,以确保不会发生数据丢失(数据不会 适合C级的绑定缓冲区).但是,这意味着4G longtext/longblob列. ext/mysqli已更改为有一种方法 解决这个问题.您需要调用mysqli_stmt_store_result() 将在本地存储数据,这当然意味着更高的内存 PHP的用法.但是,由于您使用libmysql,因此不会 当然,PHP的内存限制.在store_result期间,最大长度为 将计算每列,然后在执行bind_result时 仅分配大小为max_length的缓冲区,这将是 绝对低于4G.简而言之,准备执行store_result bind_result提取...提取...提取

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

这篇关于耗尽的允许内存大小为134217728字节(尝试分配4294967296字节)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆