• Hello,
    I’m trying to upload a file via PHP using a built in WordPress function called wp_generate_attachment_metadata( $attachment_id, $file )
    I get a 503 Service Unavailable if I upload a 5MB jpg. The PHP settings are set to 8M max post size and upload size. There are no errors in error log.

    When I disabled this built in wordpress function the upload works, however, the thumbnails are not being generated, even when I try to manually generate them using “Regenerate Thumbnails”, the process fails.

    This has happened on two shared hosting environment! is there any way to get minimum requirements for this function to run?

    Any reason this makes the server fail?

    Thanks

    • This topic was modified 3 years, 4 months ago by Jan Dembowski. Reason: Moved to Fixing WordPress, this is not an Everything else WordPress topic
Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter Oded Talmon

    (@odedta)

    Upon further investigation it seems that the code breaks on class-wp-image-editor-imagick.php on line 492:
    $orig_image = $this->image->getImage();

    This returns an empty Imagick Object, the code never passes line 506:
    $resized = $this->resize( $size_data['width'], $size_data['height'], $size_data['crop'] );

    • This reply was modified 3 years, 4 months ago by Oded Talmon.
    Dion

    (@diondesigns)

    First, if you are using a version of PHP older than 7.2, update PHP. That might solve your problem. If you are using PHP 7.2 or later, read on.

    The error means your shared hosting doesn’t have enough server resources to generate the thumbnails from your (very large) image. Your choices are:

    1) Upgrade your hosting so you have the necessary resources
    2) Pre-process large images before uploading them

    Option (2) makes the most sense if this issue occurs infrequently.

    Thread Starter Oded Talmon

    (@odedta)

    Hello Dion!
    Thanks for taking the time to respond.
    Actually, this issue happened in the previous hosting and I noticed that if using 7.2 the problem doesn’t exist, only when I’ve upgraded to 7.3 or 7.4 the problem was there.

    What do you mean when you say Pre-process large images? What exactly needs to be done?

    Thanks!

    Dion

    (@diondesigns)

    By “pre-process” I mean optimizing and then reducing the width/height and filesize of the image before it’s uploaded. There are a number of image manipulation applications available for Windows/Mac/Linux systems that will accomplish this.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘wp_generate_attachment_metadata() function causes 503 Service Unavailable’ is closed to new replies.