php 写入 xml 文件时允许的内存大小为 67108864 字节(尝试分配 4459414 字节)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5833868/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 22:37:38  来源:igfitidea点击:

Allowed memory size of 67108864 bytes exhausted (tried to allocate 4459414 bytes) in writing an xml file

phpxml

提问by karto

Possible Duplicate:
Allowed memory size of 33554432 bytes exhausted (tried to allocate 43148176 bytes) in php

可能的重复:
在 php 中允许的内存大小为 33554432 字节(试图分配 43148176 字节)

I've seen similar problems here, but mine is quite different. I am reading from database and writing to an xml file. I get this error

我在这里看到过类似的问题,但我的完全不同。我正在从数据库读取并写入一个 xml 文件。我收到这个错误

<b>Fatal error</b>:  Allowed memory size of 67108864 bytes exhausted (tried to allocate 4459414 bytes) in <b>.../public/home/..</b> on line <b>32</b><br />.

What should be the solution? Do I increase the memory size in code? Any help?

解决办法应该是什么?我是否在代码中增加内存大小?有什么帮助吗?

采纳答案by Parris Varney

Do a mysql_unbuffered_query()rather than mysql_query(). Your query is probably returning too much data as is for your php server to handle.

做一个mysql_unbuffered_query()而不是mysql_query()。您的查询可能返回太多数据,因为您的 php 服务器无法处理。

回答by Wh1T3h4Ck5

Try to increase or remove memory_limit in php.ini.

尝试在php.ini.

Find something like this and change value of memory_limit

找到这样的东西并更改 memory_limit 的值

; Maximum amount of memory a script may consume (128MB)
; http://php.net/memory-limit
memory_limit = 128M

(this is part of my php.ini)

(这是我的 php.ini 的一部分)

Restart server after saving changes.

保存更改后重新启动服务器。

Also, you can try to remove limit from code.

此外,您可以尝试从代码中删除限制。

Example:

例子:

ini_set('memory_limit', '-1');

That should work fine.

那应该可以正常工作。

Another way is setting memory limit from .htaccessfile by adding line:

另一种方法是通过添加行从.htaccess文件设置内存限制:

php_value memory_limit 128M

php_value memory_limit 128M

(128M is just an example)

(128M只是一个例子)

Note: For shared hosting I highly doubt you can change memory limit.

注意:对于共享主机,我非常怀疑您是否可以更改内存限制。