允许的内存大小为67108864字节已用尽 [英] Allowed memory size of 67108864 bytes exhausted

查看:601
本文介绍了允许的内存大小为67108864字节已用尽的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须在这里阅读过所有类似的帖子,但仍然无法弄清为什么会发生这种情况.

I must have read all the similar posts here but still cant figure out why this is happening.

我的代码:

$stmt = $this->db->stmt_init();
        $stmt->prepare("SELECT Table1.id,Name,type,text,fname,lname FROM Table1, Table2 WHERE Table1.email = Table2.email AND type='text' AND Table1.Id=?");
        $stmt->bind_param("i", $id);
        $stmt->bind_result($legTxtId,$legTxtName, $legTxtType, $legTxtText, $legTxtFname, $legTxtLname);
        $stmt->execute();
        $results = array();
        while($stmt->fetch())
        {
            $results[] = array(
                    'legTxtId' => $legTxtId , 'legTxtName' => $legTxtName , 'legTxtType' => $legTxtType , 
                    'legTxtText' => $legTxtText , 'legTxtFname' => $legTxtFname ,
                    'legTxtLname' => $legTxtLname );
        }
        $stmt->close();
        return $results;

现在,我在另一个函数中使用了完全相同的代码,而该函数在此函数之前被调用,即使返回了另一个字段,它也可以正常工作.

Now I am using the exact same code in a different function that is called before this one and it works fine even though it returns one more field.

尤其是这一行仅返回1行,仅包含纯短文本(没有照片或任何东西),因此它不会失败,因为它肯定小于64M.

This one in particular only returns 1 row with just plain short text (no photos or anything) so it should not fail cause its definitely less than 64M.

任何人都可以看到问题所在吗?

Can anyone see what the problem is?

推荐答案

在另一个问题中讨论过,看来两个解决方案是:

As discussed in the other question it seems the two solutions are:

1)切换到 mysqlnd 连接器,因为这不会显示相同的错误.

1) Switch to the mysqlnd connector as this doesn't show the same bug.

如果您正在使用Yum安装PHP(例如在Amazon ec2服务器上),则可以通过以下方法更改LAMP堆栈的设置来实现此目标:

If you're using using Yum to install PHP (e.g. on an Amazon ec2 server) then you can achieve that by changing your setup of your LAMP stack from this:

sudo yum install php-mysql php php-xml php-mcrypt php-mbstring php-cli mysql httpd 

收件人:

sudo yum install php-mysqlnd php php-xml php-mcrypt php-mbstring php-cli mysql httpd 

2)使用store_result或use_result,这也不会显示大量的内存分配问题.

2) Use either store_result or use_result which also don't show the massive memory allocation issue.

切换到mysqlnd可能是一个更好的长期解决方案,因为它通常比现有的php-mysql连接器写得更好(例如,结果不会在复制到PHP内存之前在MySQL内存中重复),并且是PHP的默认连接器5.4.0以上.

Switching to mysqlnd is probably a better long term solution as it is general better written than the existing php-mysql connector (e.g. results aren't duplicated in MySQL memory before being copied to PHP memory) and is the default connector from PHP 5.4.0 onwards.

这篇关于允许的内存大小为67108864字节已用尽的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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