PHP 致命错误:内存不足(已分配 80740352)(尝试分配 12352 字节)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6314733/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PHP Fatal error: Out of memory (allocated 80740352) (tried to allocate 12352 bytes) in
提问by daza166
I get this error when users are uploading images on my site.
当用户在我的网站上上传图片时,我收到此错误。
error msg is "PHP Fatal error: Out of memory (allocated 80740352) (tried to allocate 12352 bytes) in /home......." How can I fix this using php.ini?
错误消息是“PHP 致命错误:/home 中的内存不足(已分配 80740352)(试图分配 12352 字节)......”如何使用 php.ini 解决此问题?
Here is my current upload php.ini settings
这是我当前上传的 php.ini 设置
upload_max_filesize = 2000M ;
post_max_size = 2000M
max_file_uploads = 8
Any ideas what else I need to add to solve this error?
任何想法我还需要添加什么来解决这个错误?
回答by srikanth
set_time_limit(0);
ini_set('memory_limit', '20000M');
To the top of your script. Change the 20000M accordingly.
到脚本的顶部。相应地更改 20000M。
回答by Emil Vikstr?m
The optimal memory_limit
value depends on what you are doing with the uploaded files. Do you read the files into memory using file_get_contents or the GD library? In that case, increase memory_limit to at least the same as upload_max_filesize, preferably more.
最佳memory_limit
值取决于您对上传文件的处理方式。您是使用 file_get_contents 还是 GD 库将文件读入内存?在这种情况下,将 memory_limit 增加到至少与 upload_max_filesize 相同,最好更多。
If you are using GD, keep in mind that GD holds the entire image uncompressed in memory. This means that it takes memory in the range of width * height * bit-depth
, e.g., 1024*768*32 = 25 165 824 bits = 3 MB
for a screenshot, or as much as 55 MB for a 14 megapixel image.
如果您使用 GD,请记住 GD 将整个图像保存在内存中未压缩。这意味着它需要的内存范围在 范围内width * height * bit-depth
,例如,1024*768*32 = 25 165 824 bits = 3 MB
用于屏幕截图,或多达 55 MB 的 14 兆像素图像。
Some operations may need to create a copy of the image, so consider setting memory_limit to the double of what you need to keep the image in memory. Also make sure to not load all images into memory at once if you don't have to. You can free the memory used by GD by calling imagedestroyon the handle when you are done working with the image.
某些操作可能需要创建图像的副本,因此请考虑将 memory_limit 设置为将图像保留在内存中所需的两倍。如果不需要,请确保不要一次将所有图像加载到内存中。完成图像处理后,您可以通过在句柄上调用imagedestroy来释放 GD 使用的内存。
回答by Cem Kalyoncu
Increase your memory limit from php.ini
从 php.ini 增加你的内存限制
memory_limit = ...
回答by SIFE
Uploaded files are saved in memory, so you should also to increase memory at least the same size of the expected file.
上传的文件保存在内存中,因此您还应该至少增加与预期文件大小相同的内存。
memory_limit = 2000M // better 2200M or above, just in case.