简体   繁体   English

PHP允许内存限制错误,内存分配很少

[英]PHP allowed memory limit error occurred with little memory allocate

When I try to upload file with PHP(CakePHP) application, those error happened. 当我尝试使用PHP(CakePHP)应用程序上传文件时,发生了这些错误。

Fatal error: Allowed memory size of 16777216 bytes exhausted (tried to allocate 9660 bytes) in /home/xsu0653/public_html/administer/app/models/behaviors/sf_upload.php on line 156 致命错误:第156行/home/xsu0653/public_html/administer/app/models/behaviors/sf_upload.php中允许的内存大小为16777216字节(尝试分配9660字节)

As you can see, in my php.ini setting, allowed memory limit is set to 16MB. 如您所见,在我的php.ini设置中,允许的内存限制设置为16MB。

This error message says my application tried to allocate only 9660 bytes. 此错误消息说我的应用程序试图只分配9660字节。 I think 9,660 bytes is only 0.009MB. 我认为9,660字节只有0.009MB。

I can't understand why this error happend with such a little memory allocate. 我无法理解为什么这个错误发生在这么小的内存分配。 And this error not happen in any time, only some times. 并且这种错误不会在任何时间发生,只会发生一些时间。 It's strange too. 这也很奇怪。

That is in reference to the amount it attempted to allocate and failed. 这是指它试图分配和失败的金额。 It went 9,660 bytes over the limit. 它超过了限制9,660字节。

PHP dynamically allocates memory as it runs through a script - it also tries to deallocate as it goes, too. PHP在通过脚本运行时动态分配内存 - 它也会尝试解除分配。

This error message says my application tried to allocate only 9660 bytes. 此错误消息说我的应用程序试图只分配9660字节。

The 9660 bytes in your error message simple refer to the latest allocation - think of it like the proverbial straw breaking the camel's back. 你的错误信息中的9660字节简单地指的是最新的分配 - 想想它就像谚语破坏骆驼的背部。 Your script has already allocated very close to your configured limit, and then tries to allocate this last little bit which puts it over the limit and so presents this error. 您的脚本已经分配了非常接近您配置的限制,然后尝试分配最后一点,使其超出限制,因此出现此错误。

Frameworks like Cake can be rather inefficient in memory usage, depending on which modules are in use - and you will find that they recommend upping the limit. 像Cake这样的框架在内存使用方面效率相当低,这取决于正在使用的模块 - 你会发现他们建议增加限制。

You can also help to improve things by unsetting large arrays or clearing buffers when you no longer need them. 您还可以通过在不再需要时取消设置大型数组或清除缓冲区来帮助改进。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM