WordPress.org

Ready to get started?Download WordPress

Forums

Out of Memory when uploading images (18 posts)

  1. Mosher
    Member
    Posted 4 years ago #

    I've ploughed the FAQs and forum and tried everything. I will try to cover everything here!

    I have three blogs sat on one hosted server (via 1&1). One's a very old version of WP and aside from being covered in cobwebs works fine. The other two are v2.8.4 and both exhibit the same problem

    As of a week or so back, I receive the following error when I upload images from my PC to the blog. The "loading" bar goes fully to 100%, the system pauses for maybe 45 seconds and then:

    Fatal error: Out of memory (allocated 32505856) (tried to allocate 4096 bytes) in /homepages/8/d151455252/htdocs/Moshtour/wordpress/wp-includes/media.php on line 345

    I have added the following lines (one at a time and both at once) to my wp-config.php:

    ini_set("memory_limit","128M");
    define('WP_MEMORY_LIMIT', '128MB');

    I tried adding the suggested line to the .htaccess file but then receives "Error 500" when accessing the web sites. I assume this is a security restriction by my ISP and fair enough.

    I don't have access to my php.ini file, so contacted my site hosts. They told me to upload a fresh one which would supersede the existing one. I did this, including the line:

    memory_limit = 256M

    I've checked that this ini file is being picked up and it definitely is. But it still doesn't fix the error - I'm still running out of memory after the 32M (specifically 32505856B) point.

    I finally disabled all plug-ins. This fixed it. Next step was to re-enable them. I got as far as three (the third being WordPress.Com Stat) before the error reappeared. I've tried a few other combinations and there is no single plug-in that's causing the issue.

    I have to wonder, though, despite every ini and cfg file telling the system to ramp up or 128M or 256M why my WP is collapsing as it can't find any space after 32M?

    Pretty please, anyone? It's such a pain not being able to upload photos to a travel blog!

    Thanks

  2. Samuel B
    moderator
    Posted 4 years ago #

    you just want this line in .htaccess
    define('WP_MEMORY_LIMIT', '128M');

    notice it's just 128M
    not
    128MB

  3. Mosher
    Member
    Posted 4 years ago #

    Nope. If I put that line into my .htaccess I get the following when trying to access any page on the site:

    Internal Server Error
    
    The server encountered an internal error or misconfiguration and was unable to complete your request.
    Please contact the server administrator, webadmin@kundenserver.de and inform them of the time the error occurred, and anything you might have done that may have caused the error.
    
    More information about this error may be available in the server error log.
    
    Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.
  4. Mosher
    Member
    Posted 4 years ago #

    Additionally, I have - after a lot of fiddling - determined that the problem is only with some pictures. It just happened to be the collection I've been working with for a while...!

    They're JPG images from my Nokia E71 phone. I even tried opening them up in IrfanView and re-saving them as fresh images. Same issue. Finally I opened them, screen-grabbed, created a new image, pasted, cropped and saved... and they now upload.

    However, the question as to why WP is running out of memory after 32Mb when my PHP and WP configs tell the system it has 256Mb to use hasn't yet been answered.

    At least I can get my pics up now :)

  5. Shane G
    Member
    Posted 4 years ago #

    Hi,

    Check with these options:

    1) Please check php.ini file in the root/public_html folder of your site. Open php.ini file in text editor and change the values for memory_limit. By default it should see memory_limit = 8M. Try changing it to 12M. if it will not resolve the problem then try to increase it either 16M or 24M.

    2) If you can’t find the php.ini file, open up the PHP file which requires more memory and add this line just after ini_set(’memory_limit’, ‘12M’); we can increase memory upto 16M or 24M to resolve the issue. But do it try with 12M first.

    3) Add this line in wp-settings.php file:

    define(’WP_MEMORY_LIMIT’, ‘XXX’);

    Thanks,

    Shane G.

  6. Mosher
    Member
    Posted 4 years ago #

    Shane - see above. I've already tried all of these.

    Although I've checked and the memory limit has been set as high as 256Mb, WordPress *still* falls over complaining about not being able to provide more than 32Mb... Bizarre.

  7. Samuel B
    moderator
    Posted 4 years ago #

    256Mb 32Mb

    this is not correct

    256M and 32M

    correct

  8. Mosher
    Member
    Posted 4 years ago #

    Yes, I know... Within the code I have used "M". On here to describe the amounts I had set them to I am using "Mb" as it's the usual abbreviation.

    I've set the memory limits to 256Mb ("256M" within the PHP) and checked with a script to see the current values assigned to variables as pulled from the operational system. It tells me that the values I have assigned have indeed been recognised and applied.

    Regardless of the fact that the system has been told it can use 256M(b) for scripts, it's still falling over complaining that WordPress has exceeded 32M(b) - more specifically 32505856 bytes.

  9. percepts
    Member
    Posted 4 years ago #

    uploads will be using the GD library functions to process images (unless you have some plugin using imagemagick).

    GD functions can be memory intensive and will grab plenty, especially for bigger images such that even doing a copyresampled will cause it to fail. And the reason it fails is because hosting providers put a limit on how much memeory each script can grab.

    There are several ways to up that limit but not all of them will work depending on other restrictions your host puts on your account.

    You can either change memory_limit in your php-ini file but this is not recommended because it means any script you run can grab that amount of memory.

    You can put it in your .htacess file but this won't work unless your host has enabled it and is not recommended for same reason as changing php_ini.
    To check if yuor host has enabled it you need to run a script on your host which calls php_info() and check the the configuration which should include -enable-memory-limit.
    If it doesn't include that enable command then you are stuffed unless you can change php-ini.

    If it does include that enable, then the best way to increase memory is to include the following in the script causing the problem.

    <?php ini_set(memory_limit,64); ?>

    note that there is no M after the amount of memory.

    also note that if you are on shared hosting and strting grabbing lots of memory your host might kick you off which is why they limit memory so there is plenty for everyone.

    Simplest answer of all is to resize images before upload to sensible sizes and then GD function won't blow its guts.

  10. percepts
    Member
    Posted 4 years ago #

    I know you've said you have done this but please look at wp-settings.php right at the very top where it says:

    if ( !defined('WP_MEMORY_LIMIT') )
    define('WP_MEMORY_LIMIT', '32M');

    if ( function_exists('memory_get_usage') && ( (int) @ini_get('memory_limit') < abs(intval(WP_MEMORY_LIMIT)) ) )
    @ini_set('memory_limit', WP_MEMORY_LIMIT);

    let us know what it says in there...

  11. percepts
    Member
    Posted 4 years ago #

    And note how its sets WP_MEMORY_LIMIT to an integer value as the manual says it should be meaning no M after it. The M works in php.ini but not in php code.

  12. Mosher
    Member
    Posted 4 years ago #

    percepts - thanks, I'll have a look shortly. Just about to go on a shopping errand!

    The images I'm having problems with, though, are only 256Kb (that's Kb, not Mb) in size! They're off my Nokia mobile phone and that's about as big an image as it'll produce. I can successfully post other images weighing in at up to 3.5Mb - I tested.

    Oh, and I can't edit the existing php.ini file - but I can supersede it by placing a new one in the root directory as advised by my host. Tested this and my new one does indeed overshadow their default. It doesn't solve the problem though.

  13. percepts
    Member
    Posted 4 years ago #

    There are two other places where wp tries to set memory limit.

    wp-admin/inludes/image.php
    wp-admin/inludes/file.php

    in my version it uses 256M

    if -enable-memory-limit is not set in your php config (compile time options) then these will fail without an error message but if php.ini says 256M then you should be OK

  14. davidedalcolle
    Member
    Posted 4 years ago #

    I had the same problem in several blogs when upoloading images. Only images, not videos.

    This is my solution:

    - open wp-admin / includes / image.php
    - find the following lines:

    // Set artificially high because GD uses uncompressed images in memory
    @ini_set('memory_limit', '256M');
    $image = imagecreatefromstring( file_get_contents( $file ) );

    Change 256M to a more reasonable value according to your real php memory limit

    That worked for me in 2 different blogs. I'd like to get a feedback on this possible solution

  15. klancast
    Member
    Posted 4 years ago #

    percepts and co.

    good info there.

    I am having numerous fatal error memeory issues, I looked in the:
    wp-admin/inludes/image.php
    wp-admin/inludes/file.php
    files and there are no memory setting lines there at all.

    My wordpress and php are set to 64M, but I am seeing fatal errors at 20971520 whicn I believe is 20M. I just cannot find where that is set.

    There are a large number of image files that are over 500K, wonder if I get my wife to reduce those sizes would that reduce the load and errors.

  16. Phil Erb
    Member
    Posted 4 years ago #

    Mosher,

    I'm assuming that you haven't found a solution to this yet. I'm puzzled why the relatively small images from your phone are giving you a problem while larger images are not. In my experience with WP on 1&1 hosting, I've been able to upload images that are a 1 - 2MB and not much more than that, or I get the same error that you've seen.

    I've been hosting multiple web sites with 1&1 for years and have been extremely happy with them, except for this issue. I'm not trying to upload HUGE images - so far just a little over 3MB.

    However, I think that the issue may not be related specifically to the file size that we see, but also take into account other things about the image (type of compression, etc.). As you've mentioned, you've been able to upload some 3MB images without a problem, where as the ones from your phone are much smaller in size, but it's likely that the phone uses some kind of odd compression on them. Similarly, it's likely that the images from my camera, with are about the same as from yours, have some kind of different compression than yours do - that may be why I can't upload my 3MB images.

    This is made all the more annoying by the fact that on the GoDaddy hosting account I have - I can upload those same images without a problem. I say that's more annoying because I have other reasons to not like GoDaddy and would prefer to keep my accounts with 1&1.

    In comparing the 1&1 and GoDaddy configurations, the PHP memory_limit on GoDaddy is 64MB and on 1&1 is 40MB. I've found a 1&1 FAQ article stating that their shared hosts do not allocate more than 40MB, even if it is set different in php.ini, .htaccess, or otherwise. That article is at http://faq.1and1.com/scripting_languages_supported/php/9.html.

    It's been a while since I've researched the issue, but when I was doing some significant testing back in January, I seem to recall that it wasn't just tied to the PHP memory_limit setting and 1&1's 40MB limit, but that there was some other limit that was contributing to the issue. Unfortunately, I can't remember off the top of my head what it was and can't find my notes. However, I'm going to keep looking, as I'm determined to come up with a decent solution to this, as I want to move my primary domain back to 1&1.

    If you are interested, the 1&1 Customer Advocate Team is at 1-866-258-5616. Unfortunately, they are only available by phone between the hours of 9am and 5pm EST and have no e-mail address, which is why I haven't had a chance to contact them yet. They may have a European phone number and hours, but I was only sent the U.S. information.

    I will keep you updated on my research and progress with 1&1. If you have any more information from your research, I would love to hear it.

  17. Amber Fellows
    Member
    Posted 4 years ago #

    @ philerb- I made a website and had to abandon it (and opt for wordpress) after a year of ...because the website builder provided by 1and1 was locking up, to the extent that I had to delete 5 pages and reorder things I don't know how many times--and now I think that I might know why! I don't know whether to cry more or be happy about this.... Never once was I given this information in the excruciating amount of tech 'help' and website 'fixes' that I received.

    Oh...my...gosh.

  18. Emily05MLE
    Member
    Posted 3 years ago #

    I have been looking...and looking...and looking for an answer to this problem.

    philerb, your comment was really informative. But the limit for 1and1.com at the site you listed (http://faq.1and1.com/scripting_languages_supported/php/9.html) is actually only 30MB, not 40! I'm not sure if they've gone down, or what. I've tried cutting my xml into up to 15 pieces (and it was only 1mb to start), but I keep getting fatal errors like this one:

    Fatal error: Out of memory (allocated 32243712) (tried to allocate 12288 bytes) in /homepages/26/d329539586/htdocs/wp-admin/includes/image.php on line 162.

    I've successfully changed from the 1and1.com default PHP v.4 to v.5. I've been able to import about 1/2 of my posts from my wordpress.com site. But I can't get the rest to load, and 1and1.com tech support was unwilling to increase the 30MB PHP limit and were generally unhelpful.

    I've now also disabled all plug-ins, hoping that might help. It hasn't.

    So...anyone able to recommend a next step? I've been basically trying to teach myself php all day, have made some progress, but this is tripping me up.

Topic Closed

This topic has been closed to new replies.

About this Topic