Sometimes when I upload a picture (either with flash or browser uploader), I get a message like (this was with a 1.46MB jpg):
Fatal error: Out of memory (allocated 69206016) (tried to allocate 4000 bytes) in /home/ab64489/public_html/wp-includes/media.php on line 254
I am on a shared host, but the max upload size is 64MB. I’ve tried uploading other files (I made a zip of some random files, with the archive totaling ~58.1MB, and it uploads and crunches with no problem, so it’s not the file size). It also seems that the upload works fine, but when it tries to crunch, then it encounters the error.
I’ve seen similar problems here and on other sites with no real solutions.
What could be the cause of this issue?
This isn’t a WordPress problem. There’s no telling on a shared environment what the culprit might be. You probably don’t have access to your php.ini config, nor do we know how many websites your hosting company has jammed on your server.
The very nature of a shared server is that each client shares the resources of that one server. If one website is using massive amounts of resources while you’re trying to upload your image, that would certainly affect it.
The only real fix to this is getting onto a more controllable environment. I gave up on shared hosting a long time ago and went with a cloud server from Rackspace. I am in complete control and I don’t have to worry about other memory hogs on the same box.
You can also look at your code and identify blocks that use significant memory by printing out
memory_get_usage()
before and after. You might need to debug in WordPress core, or in plugins. I typically start pretty wide and start zooming into problematic areas of code. You’ll find the memory leak this way if it’s in your code.My solution (in wordpress 3.3.1) was to do the image compression myself, then add a single entry to the metadata table in the DB.
For the image compression, I noted the other correctly compressed files were all compressed to three consistent sizes: 150×150, Mx300, and Nx1024, where M and N would maintain the ratio of the original image.
In the metadata table, there was already an entry for my newly created post. Sort by
post_id
and then look for the entry with yourpost_id
andmeta_key
=_wp_attached_file
to make sure yours is there.My corresponding row has meta_value =
2012/04/get_in_shape.png
.Now the fun part! Find a row (from a post which had its image correctly compressed) with
meta_key
=_wp_attachment_metadata
and use its value ofmeta_value
as a template for your new row.In your new row, the values should be
The following is a
serialize()
ed string with the data that worked for me formeta_value
. It will not work for you without tweaks. If you can do all the above, you can certainly do the tweaks as well.See the path looking thing
2012/04/get_in_shape.png
? That’s the path to your file (with wp-content as its understood prefix). Note it’s preceded bys:24
which is the string length of the value. Change the path to match your file, then change the 24 to match the length of the path you used.Do that for each of the file sizes, save the new record, and you’re golden.
DO NOT TRY THIS if you have little/no idea how to do it. Just sayin’ there is a cheaper(*) method than moving to a new host.
(*) if learning all this in uni is considered cheap.
For me it was really a memory issue (in the code), I was using a plugin called
blurhash
that did some stuff on the images, so make sure to disable all your plugins and you might find the problem, and then push a fix or something or fork it.For instance in my case the blurhash was running multiple times on the image so I added a simple cache mechanism and my problem was gone.