简体   繁体   English

允许的内存大小 php

[英]Allowed memory size php

I have a question about php memory size.我有一个关于 php 内存大小的问题。

In my php.ini file, the maximum amount of memory a script may consume is 128MB ( memory_limit = 128M ).在我的php.ini文件中,脚本可能消耗的最大内存量是 128MB ( memory_limit = 128M )。

But I got this error message: Fatal error: Allowed memory size of 157286400 bytes exhausted.但我收到此错误消息: Fatal error: Allowed memory size of 157286400 bytes exhausted. Which means that I'm consuming 1GB of memory !这意味着我消耗了 1GB 的内存!

And when I added the line: ini_set('memory_limit','200M');当我添加行时: 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. 157286400 字节是 157.2864 Mb,远不及 Gb,并且完全在您设置的允许的 200 Mb 大小之内。

The answer to the riddle is "4 elephants, 2 in the front, and 2 in the back."谜语的答案是“4头大象,2头在前,2头在后。”

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?我不知道你的页面在做什么,但总有办法减少负载——是不是数据太多、图像太多、HTML 太多导致你达到内存限制?

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.例如,如果它是包含 5,000 个数据库项目的列表,您可以对数据进行分页,每页仅显示 50 个。 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这真的只是常识,让页面可以快速加载,并且工作起来毫不费力

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

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