128MB PHP内存限制是否很多? [英] Is a 128MB PHP memory limit a lot?

查看:240
本文介绍了128MB PHP内存限制是否很多?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天,我在要构建的内容管理系统中添加了一项新功能.根据您将图像上传到的位置,PHP将调整图像的大小以适合指定的位置.效果很好,但是当我尝试上传较大的图像(如3MB图像)时,出现了致命错误:

Today I added a new feature in the content management system I'm building. Depending on where you are uploading an image to, PHP will resize the image to fit the designated location. It works quite well, but when I try to upload a larger image, as in a 3MB image, I'm getting a fatal error:

Fatal error: Allowed memory size of 134217728 bytes exhausted 
(tried to allocate 42520 bytes) in...

我认为128MB的内存已经足够了,考虑到我没有那么大的运行……至少我不这么认为.它尝试为调整大小过程分配另外的42520字节,但失败了.

I'm thinking 128MB of memory is quite a lot, considering I don't run that much... at least I don't think so. It tried to allocate another 42520 bytes for the resizing process, but failed.

我的问题是我应该(A)增加限制还是(B)重新评估为什么我首先使用了这么多的内存? 128MB是个好数字还是太大/太小了?

My question is should I (A) increase the limit or (B) re-evaluate why I'm using so much memory in the first place? Is 128MB a good number or is it too large/too little?

谢谢, 瑞安

解决方案

我得出的结论是128MB对于调整图像大小实在太大了,我非常专注于查看其他选项,例如exec()选项,以至于我从未仔细研究过我的样本"数据.事实证明,即使我的大图像只有2.83MB,也超过10000px.那是个问题. :)

I concluded that 128MB is really too much for resizing an image and I was so focused at looking at other options... like exec() options, that I never took a closer look at my "sample" data. Turns out, that even though my large image was only 2.83MB, it was OVER 10000px wide. That's a problem. :)

推荐答案

GD将图像作为位图存储在内存中,因此我不能完全排除某些JPG图像(例如高分辨率,高度压缩)的可能性,则位图版本可能会很大.

GD stores images as bitmaps in memory, so I wouldn't completely rule out the possibility that with some JPG images (for example, high resolution, highly compressed), the bitmap version could be quite large.

在打开之前,立即调用 memory_get_usage() &开始调整图像大小看看内存量是否太大了.

Call memory_get_usage() right before you open & start resizing the image & see if that amount of memory is way too big.

仅供参考,当脚本显示(试图分配42520字节)"时,这并不意味着它仅需要42520个字节即可成功运行.这只是意味着那一刻它需要42520个更多的字节.稍后,它可能试图分配更多的内存.因此,仅向内存总数增加42520个字节就可能无法解决任何问题.

Also just FYI, when the script says "(tried to allocate 42520 bytes)", that doesn't mean it just needed 42520 more bytes to run successfully. It just means at that moment it needed 42520 more bytes. A bit later it might have tried to allocate more memory. So, just adding 42520 more bytes to the memory total likely wouldn't have fixed anything.

这篇关于128MB PHP内存限制是否很多?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆