【发布时间】:2014-07-03 20:43:24
【问题描述】:
您好,我在尝试使用 imagecreatefromstring 时遇到错误 Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 21944 bytes)
$imageFile = imagecreatefromstring($image);
if ($imageFile !== false) {
$width = ImageSX($imageFile);
$height = ImageSY($imageFile);
}
if ($this->isExifInstalled) {
@$type = exif_imagetype($source);
$mime = image_type_to_mime_type($type);
}
if ($mime === "application/octet-stream") {
$mime = $this->image_file_type_from_binary($image);
}
if ($mime === "application/octet-stream") {
$mime = $this->getMimeTypeFromUrl($source);
}
imagedestroy($imageFile);
【问题讨论】:
-
尝试增加你的 memory_limit。也许它没有泄漏,确实需要这么多内存。
-
我认为超过 128MB 内存不是一个好主意。嗯,但那将是我最后的手段。我也尝试了 256MB,但仍然出现错误,但允许的内存大小增加了......
-
好吧。尝试将其设置一次,例如2G(只是为了测试),当它被超过时,你的应用程序中存在内存泄漏(你将图像存储在 RAM 中的某个地方)或者 PHP ext/gd 中存在错误
-
好吧,我尝试将内存限制升级到 512MB,它现在可以工作,但这真的有必要吗?或者我可以做些什么来让它在不增加内存的情况下运行?
-
根据图像的大小,这是必要的。您也不能假设这些函数应该使用尽可能少的内存。
标签: php memory-leaks imagecreatefrompng