简体   繁体   中英

PHP allowed memory limit error occurred with little memory allocate

When I try to upload file with PHP(CakePHP) application, those error happened.

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

As you can see, in my php.ini setting, allowed memory limit is set to 16MB.

This error message says my application tried to allocate only 9660 bytes. I think 9,660 bytes is only 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.

PHP dynamically allocates memory as it runs through a script - it also tries to deallocate as it goes, too.

This error message says my application tried to allocate only 9660 bytes.

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. 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.

You can also help to improve things by unsetting large arrays or clearing buffers when you no longer need them.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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