[wp-trac] [WordPress Trac] #28907: media_handle_upload calls wp_read_image_metadata on video files, causing errors and timeouts.

WordPress Trac noreply at wordpress.org
Tue Jul 15 06:04:46 UTC 2014


#28907: media_handle_upload calls wp_read_image_metadata on video files, causing
errors and timeouts.
--------------------------+-----------------------------
 Reporter:  slangley      |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Media         |    Version:  trunk
 Severity:  normal        |   Keywords:
  Focuses:  performance   |
--------------------------+-----------------------------
 When uploading media files, if the mime type is anything other than
 audio/* then wp_read_image_metadata will be called on the file, even if
 the file is not an image.

 This in turn calls getimagesize which will read the entire file trying to
 determine if it's (a) an image, and (b) it's dimensions. If we know the
 uploaded media has a mime type video/* (and probably others) then doing
 this is pointless. If it turns out your uploaded media is stored remotely,
 (e.g. on your CDN) then this results in failed uploads and timeouts as it
 takes a while to completely read large video files.

 The most straightforward fix is to just check if the mime type is for a
 video and skip the call to wp_read_image_metadata, something like

 {{{
 #!div style="font-size: 80%"
 Code highlighting:
   {{{#!php
   } else if ( preg_match( '#^video#', $type ) === false ) {
     if ( $image_meta = @wp_read_image_metadata( $file ) ) {
       if ( trim( $image_meta['title'] ) && ! is_numeric( sanitize_title(
 $image_meta['title'] ) ) )
         $title = $image_meta['title'];
       if ( trim( $image_meta['caption'] ) )
         $content = $image_meta['caption'];
     }
 }
 }}}
 }}}

--
Ticket URL: <https://core.trac.wordpress.org/ticket/28907>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list