• Resolved owstopit

    (@owstopit)


    Hello!

    I’m having a problem when updating a post on my website. When I alter a post and press “update,” I get the following message:

    Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 72 bytes) in /public_html/wp-includes/post.php on line 1904

    I changed the path slightly as I don’t want to include the domain. The site features lots of large photos and each post contains a gallery with many large photos that are pulled in and lazyloaded then arranged with a masonry plugin.

    Ever since upgrading wordpress, the issue has been occurring. I tried including the following line in wp-config.php:

    define( 'WP_MEMORY_LIMIT', '96M' );

    but the problem persisted. I also tried the steps in this article:

    https://perishablepress.com/wordpress-error-fix-increase-php-memory-for-cachephp/

    but also had no luck. I don’t fully understand how the memory limit works with WordPress and would love it if someone could help me understand how the memory is measured. Can anyone help me clear up this issue? Are there any concerns that I should be aware of regarding memory with this site? I don’t want to run into memory problems with all of the large images in the future, so any advice would be appreciated!

Viewing 9 replies - 1 through 9 (of 9 total)
  • Moderator James Huff

    (@macmanx)

    That define line doesn’t work the way you think it does. It *limits* WordPress’s memory usage within PHP’s allocated memory, it doesn’t expand it. By default, WordPress will use as much memory as it can within PHP’s allocation, but that line forces it to use less.

    If you’re seeing this error either suddenly (no specific task was done to cause the error) or frequently, try deactivating all plugins to rule-out a plugin-specific issue and try switching themes to rule-out a theme-specific issue.

    Otherwise, here are three ways to increase PHP’s memory allocation:

    1. If you can edit or override the system php.ini file, increase the memory limit. For example, memory_limit = 128M

    2. If you cannot edit or override the system php.ini file, add php_value memory_limit 128M to your .htaccess file.

    3. If neither of these work, it’s time to ask your hosting provider to temporarily increase PHP’s memory allocation on your account. Keep in mind that most decent hosting providers allocate 32 MB to PHP under each account, and most decent hosting providers allow users to temporarily increase the memory allocation. If your hosting provider won’t accommodate you, perhaps it’s time to find a new hosting provider.

    (in the above examples, the limit is set to 128MB)

    Thread Starter owstopit

    (@owstopit)

    Thanks James,

    So I chatted with GoDaddy (that’s the hosting company for this particular site) and explained the issue. The person I talked to uploaded a php.ini file to the website root with the following lines:

    post_max_size = 128M
    upload_max_filesize = 1G
    memory_limit = 512M
    max_execution_time = 300
    max_input_time = 300
    max_input_vars = 2000

    So far, it hasn’t helped anything and the problem still persists. To explain a bit more about what is actually happening when I get the error: the website features photo galleries in different categories for each photographer. Each gallery is represented by a post which contains a wordpress photo gallery. The images and the order of images is pulled from the photo gallery.

    Any time I try to make a change to one of the galleries or even if I just open a post, do nothing to it and press “update,” I get the same error. I did notice that the browser sits there processing the post update for a pretty long time before I get the error. I’m wondering if this might shed light on why it’s not working despite the increased memory limit.

    The galleries tend to have quite a lot of photos. I’m wondering if maybe moving to a different format might eliminate the problem. I’ve thought of using something like simple fields to upload the photos, or maybe finding a plugin that makes it easy to deal with large numbers of photos. Given the php.ini file that was uploaded, can you shed any light on why the error persists? Thanks!

    Moderator James Huff

    (@macmanx)

    Are you using any plugins to build/control the galleries, or just WordPress’s built-in gallery functionality?

    Have you removed the define( 'WP_MEMORY_LIMIT', '96M' ); line completely from wp-config.php?

    Also, install and activate https://www.ads-software.com/plugins/server-ip-memory-usage/

    What does it say for the memory usage and PHP version?

    Thread Starter owstopit

    (@owstopit)

    Hey James!

    I am not using any plugins to build or control the galleries, I’m using the built-in galleries. I wrote a custom theme and basically pull the images from the post gallery as well as maintain the order of the images based on the gallery order. I did notice that I hadn’t in fact removed the WP_MEMORY_LIMIT definition from wp-config.php and just now did so. So far, the problem persists, not sure if these changes take some amount of time to go into effect. Here is the information from the plugin you recommended:

    Memory: 19.93 of 512 MB (4%) | WP LIMIT: 40 MB | PHP 5.4.43 @64BitOS

    Thanks for your help, hopefully that sheds some light on the situation!

    Moderator James Huff

    (@macmanx)

    Hm, try adding it back into wp-config, but let’s go for higher:

    define( 'WP_MEMORY_LIMIT', '256M' );

    Thread Starter owstopit

    (@owstopit)

    Unfortunately I’m getting the same error message. The error message doesn’t make sense to me since cpanel and the plugin on the wordpress dashboard seem to suggest that there is more than enough memory. I’m starting to wonder if it’s related to execution time. Any other ideas?

    Thread Starter owstopit

    (@owstopit)

    Alright, I found the problem. In order to get the gallery order working for the photos, I used a script I found online. Here is a gist with the fix:

    https://gist.github.com/vickybiswas/4211031

    When I was first using this fix, I was having trouble finding the right action to attach the function to so that the gallery order would be saved when I updated the post. Because of that I had all of these actions running a script that iterates through all of the photos:

    add_action(‘edit_post’, ‘pmc_gallery_menu_order_fix’);
    add_action(‘save_post’, ‘pmc_gallery_menu_order_fix’);
    add_action(‘publish_post’, ‘pmc_gallery_menu_order_fix’);
    add_action(‘edit_page_form’, ‘pmc_gallery_menu_order_fix’);
    add_action(‘pre_post_update’, ‘pmc_gallery_menu_order_fix’);

    So it was iterating through large amounts of data multiple times every time I tried to edit the post. I removed all but these two:

    add_action(‘edit_post’, ‘pmc_gallery_menu_order_fix’);
    add_action(‘publish_post’, ‘pmc_gallery_menu_order_fix’);

    And that seems to have fixed the issue!

    I’d love to find a better alternative to this fix, but so far that’s what I’ve found to work. I could redo the galleries altogether but that would probably require making complicated changes to the database in order to keep all of the image in order without having to remake the galleries and reorder them.

    Thank you for your help, I learned some valuable things in the process!

    Moderator James Huff

    (@macmanx)

    Thanks for sharing your solution!

    Hey.

    Saw many posts with James Huff on them , yes seems to be right pain in rear end. pardon pun , but really is back end issue I am finding , yet a much as I say that it for ME at least , came from the ” front end asthetics ” aka the teme I was using.

    Using ” Divi” from Elegant themes.
    Also using Godaddy as the dude above ( owstopit ) .
    Not sure what he running , I on VPS / CentOS.

    Been having many issues with this theme. Great thhem yet seems to be mad for power.Defo need to max up the php memory limit of any planning on using this.

    I just went basic route for solution , added to share as seen lots of people all over web having same issue so thought would share for once hey !!!

    ////=Solution ( with my abovee set up ) …

    As James Huff said to do ….all about the the wp config .

    I added the max up here ////


    define(‘AUTH_KEY’, ‘put your unique phrase here’);
    define(‘SECURE_AUTH_KEY’, ‘put your unique phrase here’);
    define(‘LOGGED_IN_KEY’, ‘put your unique phrase here’);
    define(‘NONCE_KEY’, ‘put your unique phrase here’);
    define(‘AUTH_SALT’, ‘put your unique phrase here’);
    define(‘SECURE_AUTH_SALT’, ‘put your unique phrase here’);
    define(‘LOGGED_IN_SALT’, ‘put your unique phrase here’);
    define(‘NONCE_SALT’, ‘put your unique phrase here’);
    define( ‘WP_MEMORY_LIMIT’, ‘256M’ );

    ____________________________________________

    To comfirm out of options I seeing with Godaddy , WP , and php memory issues + then DIVI via elegant themes , then option 1 = increase php.ini = NO DOES NOT WORK. Option 2 = .htacccess =NO DOES NOT WORK Option 3 speak to your host = as owstopit , was saying godaddy = nah man. speak to them lol =NO DOES NOT WORK

    so , just add the wp config max up

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Allowed Memory Exhausted on site with many images’ is closed to new replies.