This is similar to http://drupal.org/node/1401618 but there was no response to it so I am opening a more detailed report to perhaps pinpoint my particular issue.

I have a production website that allows various users to upload images to nodes.

NOT using cheap shared hosting
Setup:
VPS Dual Core, 4GB Ram
CENTOS 5.9 x86_64 with access to WHM 11.36.0 (build 21)
Drupal 6.26
PHP 5.3.8 (From Drupal Status Reports Page)
PHP memory limit 512M (From Drupal Status Reports Page)

PHP.INI
memory_limit = 512M
upload_max_filesize = 25M
post_max_size = 25M

Uploading a JPG image that is only 3.5mb, not using any progress bar just a bare bones drupal install. Upload starts and takes anywhere between 20 seconds and 60 seconds to get one of the following errors.

Error# 1 - Produced when clicking Upload
Create a node -> Click Browse on the cck image -> Upload -> I get a vanilla "An HTTP error 0 occured. /filefield/ahah/[node_type]/[cck_imagefield]/0

Error# 2 - Produced when clicking save instead of upload
Fatal error: Out of memory (allocated 60293120) (tried to allocate 16640 bytes) in /home/[name]/public_html/sites/all/modules/imageapi/imageapi_gd.module on line 59

If I shrink the file down to about 2.8MB it will work most of the time. Tried 3 different hosting companies, this VPS has been the best so far, as other servers failed on 1mb files. But now I am unable to get beyond the 3mb.

Comments

quicksketch’s picture

PHP memory limit 512M (From Drupal Status Reports Page)

Fatal error: Out of memory (allocated 60293120) (tried to allocate 16640 bytes) in

There's inconsistency here. 60293120 bytes is only 57.5MB. Considering a 3.5MB image might be 4288 x 2848 pixels, keep in mind that GD has to use an *uncompressed* version of the image in order to manipulate it. This means about 4 bytes per pixel (assuming RGBA) 4288 x 2848 x 4 = 48848896 bytes (or 46.5MB). Add in the extra overhead of Drupal (32MB) and you'll run out of memory.

But... as you say you have a limit of 512MB. But what seems to be happening is something is setting a lower limit while an image is being generated. Check if you have code anywhere that is using ini_set() to increase/decrease the memory limit to this lower number.

Steve Bizuns’s picture

Thanks quicksketch, in WHM I increased the memory_limit value to 256mb (something I have tried before)

Now I re-tested with an image that is 3.14mb (4160 x 3240) 96dpi

The error I get is
Fatal error: Out of memory (allocated 94896128) (tried to allocate 16640 bytes) in /home/[name]/public_html/[name]/sites/all/modules/imageapi/imageapi_gd.module on line 59

Does this seem to indicate that my server is only allowing 96mb memory_limit even though I have set it in PHP Config to 256?

quicksketch’s picture

Does this seem to indicate that my server is only allowing 96mb memory_limit even though I have set it in PHP Config to 256?

Yes that sounds exactly like what it's saying. Depending on your host, they may cap your configuration limits to avoid your site from affecting the service of other sites on the same server. You might try running a simple PHP script designed to hit the ceiling like this, and see where it caps out. Just put it in a stand-alone php file and run it. If you hit a limit at 96MB, it sounds like a limit set by your host. If you hit a higher limit, then you probably have an ini_set() somewhere in your own code that is setting the limit lower.

There's a million ways you could exhaust the memory manually, but here's a simple approach:

$variable = '';
while (TRUE) {
  $variable .= 'lorem ipsum ';
}

Eventually $variable will get big enough to exhaust your memory.

Steve Bizuns’s picture

Status: Active » Closed (fixed)

I was finally able to work with my hosting company to resolve this. Once it was fixed I did my best to interrogate them, this is what they say they changed;

  • "System wide PHP.INI files updated" - I could not get them to tell me the exact path of the this file they referred to.
  • upload_max_filesize = 100M (from 20mb) - I don't see how this could have helped with a 3.5mb image.
  • Setting in WHM panel >> PHP Configuration Editor. The limit was changed from 256 to 512 Mb - Note that this should NOT have fixed the problem since the 'hard cap seemed to be 57.5mb
  • The PHP.INI they uploaded to my website folder was significantly different than the one I use on my sites. The updated php.ini is in the following link.
    http://dexcms.com/drupal/large-images-fatal-error-out-of-memory
    Although this is resolved I will continue to update the information in this link as I investigate. I will attempt to narrow down what exactly fixed this.