PHP 致命错误:内存不足(已分配 80740352)(尝试分配 12352 字节) [英] PHP Fatal error: Out of memory (allocated 80740352) (tried to allocate 12352 bytes) in

查看:20
本文介绍了PHP 致命错误:内存不足(已分配 80740352)(尝试分配 12352 字节)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户在我的网站上上传图片时,我收到此错误.

错误消息是PHP 致命错误:/home 中的内存不足(已分配 80740352)(试图分配 12352 字节)......."如何使用 php.ini 解决此问题?

这是我当前上传的 php.ini 设置

upload_max_filesize = 2000M ;post_max_size = 2000Mmax_file_uploads = 8

有什么想法我还需要添加什么来解决这个错误?

解决方案

最佳 memory_limit 值取决于您对上传文件的处理方式.您是使用 file_get_contents 还是 GD 库将文件读入内存?在这种情况下,将 memory_limit 增加到至少与 upload_max_filesize 相同,最好更大.

如果您使用 GD,请记住,GD 会将整个图像保存在内存中未压缩.这意味着它需要width * height * bit-depth 范围内的内存,例如,1024*768*32 = 25 165 824 bits = 3 MB 用于截图,或者对于 14 兆像素的图像多达 55 MB.

某些操作可能需要创建图像的副本,因此请考虑将 memory_limit 设置为将图像保留在内存中所需的两倍.如果不需要,请确保不要一次将所有图像加载到内存中.处理完图像后,您可以通过在句柄上调用 imagedestroy 来释放 GD 使用的内存.>

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?

Here is my current upload php.ini settings

upload_max_filesize = 2000M ;
post_max_size = 2000M
max_file_uploads = 8

Any ideas what else I need to add to solve this error?

解决方案

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.

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.

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 imagedestroy on the handle when you are done working with the image.

这篇关于PHP 致命错误:内存不足(已分配 80740352)(尝试分配 12352 字节)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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