2010-09-20 60 views
0

我的一个脚本需要大内存。而可能是因为这个我收到以下错误php memory_limit问题

Fatal error: Out of memory (allocated 42729472) (tried to allocate 32 bytes)

我试图用的ini_set(“memory_limit的”,“256M”)来改变memory_limit的;在我的页面顶部,但我仍然得到相同的问题。我也试过ini_set('memory_limit','512M');但没有运气。

+1

什么操作导致此错误?你需要调试你的代码来隔离造成这种情况的原因。另外,你在哪里调用'ini_set('memory_limit','512M');',本地机器?托管网站? – 2010-09-20 07:42:10

回答

2

这在大约42M后崩溃,这表明PHP解释器没有得到备忘录。在带有phpinfo()输出的测试页中尝试相同的ini_set()并查找内存限制。

您能否将它设置在php.ini文件中?

+0

是从php.ini设置它的工作?什么可能是它没有从ini_set() – Prakash 2010-09-20 08:20:21

+0

http://php.net/manual/en/ini.core.php工作的问题 – teemitzitrone 2010-09-20 09:24:24

4

你有权访问php.ini文件吗?然后在那里更改memory_limit值。

你还应该分析你的脚本。很多数据库事务?他们中的很多人在循环?很多循环?很多临时变量?巧妙使用unset可以产生巨大的差异。

也很高兴知道:Performance ConsiderationsGarbage Collection

编辑(可能的回答你的问题,为什么memory_limitini_set工作)

memory_limit integer This sets the maximum amount of memory in bytes that a script is allowed to allocate. This helps prevent poorly written scripts for eating up all available memory on a server. Note that to have no memory limit, set this directive to -1.

Prior to PHP 5.2.1, in order to use this directive it had to be enabled at compile time by using --enable-memory-limit in the configure line. This compile-time flag was also required to define the functions memory_get_usage() and memory_get_peak_usage() prior to 5.2.1.

When an integer is used, the value is measured in bytes. Shorthand notation, as described in this FAQ, may also be used.

来源:php.net

0

我以前有similar issue。在我的情况下,这是suhosin补丁,阻止我的脚本获得更多的内存。