简体   繁体   中英

Allowed memory size php

I have a question about php memory size.

In my php.ini file, the maximum amount of memory a script may consume is 128MB ( memory_limit = 128M ).

But I got this error message: Fatal error: Allowed memory size of 157286400 bytes exhausted. Which means that I'm consuming 1GB of memory !

And when I added the line: ini_set('memory_limit','200M'); it worked. I don't understand how can that be possible!

错误信息

Because of math. 157286400 bytes is 157.2864 Mb, nowhere near a Gb and well within the allowed 200 Mb size you set.

The answer to the riddle is "4 elephants, 2 in the front, and 2 in the back."

My point though, is that it's clearly ridiculous to be putting elephants in a mini, as a mini, or any other car, is not designed to carry elephants.

The same applies to the browser - treat it like a vehicle that will perform nicely when you give it a light load, but will struggle or break when you overload it.

I have no idea what your page is doing, but there are always ways to reduce the load - is it too much data, too many images, too much HTML that is causing you to up the memory limit?

It is possible to increase the memory, but that's just bad practice - think about what you are doing, and how you can make the page more efficient. If it's a list of 5,000 database items, for example, you could paginate the data, only displaying 50 per page. If each item shows an avatar, or some kind of image, the memory usage goes up quickly.

It's just common sense really, making pages that will load quickly, and work effortlessly

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