imagejpeg内存耗尽 [英] imagejpeg memory exhaustion

查看:105
本文介绍了imagejpeg内存耗尽的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我找到一张大图像时,我正在创建循环显示大量图像的缩略图:

I'm creating thumbnails cycling through a lot of images, when I find a large image I get:

Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 13056 bytes)

现在我已经知道如何绕过这个:

ini_set('memory_limit', '-1');

我想知道的是它耗尽内存的原因!是否有一些调试工具可以准确显示内存耗尽的时间?具体来说,这会告诉我是否有变量/数组会破坏我的记忆?

What I want to know is why it exhaust the memory! Is there some debug tools that will show me exactly when memory is exhausting? And specifically that will show me if there are variables/arrays that are killing my memory?

或者,是否有更好的方法来调整其他图像的大小:

OR, are there better way to resize images other then:

$thumb=imagecreatetruecolor($newwidth,$newheight); 
$source=imagecreatefromjpeg($imgfile);
imagecopyresampled($thumb,$source,0,0,0,0,$newwidth,$newheight,$width,$height);
imagejpeg($thumb,$destinationfile,85);

非常感谢!

推荐答案


是否有一些调试工具将
准确显示内存为
耗尽?

Is there some debug tools that will show me exactly when memory is exhausting?

您可以使用 memory_get_usage memory_get_peak_usage


具体来说,这将告诉我
是否有变量/
的数组会破坏我的记忆吗?

And specifically that will show me if there are variables/arrays that are killing my memory?

有时变量只是资源持有者,实质上指向数据结构可能是用其他语言创建的。 PHP无法衡量这些。只需在代码中的可疑行之后使用内存使用函数来缩小罪魁祸首。

Sometimes variables are just resource holders that, in essence, point to data structures that may be created in other languages. PHP cannot measure these. Just use the memory usage functions after suspect lines in your code to narrow down the culprit.

某些设置(如共享主机)会限制您修改内存要求的能力。这些限制可以在PHP,Web服务器和/或OS级别实现。您需要通过调用phpinfo()来确保您的memory_limit请求成功。

Certain setups (like shared hosting) restrict your ability to modify memory requirements. These restrictions can be implemented at the PHP, web server and/or OS level. You'll want to ensure that your memory_limit request is successful by calling phpinfo().

这篇关于imagejpeg内存耗尽的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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