If the WordPress automatic update failed

This problem encountered since I moved my server to IIX, which has less bandwidth for international user, and for that reason too, the downstream is too small to download whole WordPress package that used for updating. That’s why, I always get timeout error. So, I’m simply unable to automatically update my WordPress.

However, the solution is actually simple, by increasing the timeout so the download can be completed. Once it is, the updating will going smoothly. So this is how to do it, in manual way.. 🙂

Open /wp-admin/includes/file.php with your favourite text editor.

Find the following function

* Downloads a url to a local file using the Snoopy HTTP Class.
* @since unknown
* @todo Transition over to using the new HTTP Request API (jacob).
* @param string $url the URL of the file to download
* @return mixed WP_Error on failure, string Filename on success.
function download_url( $url ) {
//WARNING: The file is not automatically deleted, The script must unlink() the file.
if ( ! $url )
return new WP_Error(‘http_no_url’, __(‘Invalid URL Provided’));

$tmpfname = wp_tempnam($url);
if ( ! $tmpfname )
return new WP_Error(‘http_no_file’, __(‘Could not create Temporary file’));

$handle = @fopen($tmpfname, ‘wb’);
if ( ! $handle )
return new WP_Error(‘http_no_file’, __(‘Could not create Temporary file’));

$response = wp_remote_get($url, array(‘timeout’ => 60));

if ( is_wp_error($response) ) {
return $response;

if ( $response[‘response’][‘code’] != ‘200’ ){
return new WP_Error(‘http_404’, trim($response[‘response’][‘message’]));

fwrite($handle, $response[‘body’]);

return $tmpfname;

Okay, notice the line we need to change?

Yep, this one

$response = wp_remote_get($url, array(‘timeout’ => 60));

By default it is set to 60 seconds, so we can increase it depends to our downstream. For me, I only able to download 800 kB or so in 60 seconds (as shown when the update failed), so for WordPress package that usually more than 2 MB, I need to multiply it to at least three times. But for playing safe, I multiply it to five, or 300 seconds. Then, I change the above line to this

$response = wp_remote_get($url, array(‘timeout’ => 300));

Upload and replace the old files. Try to do update again and it should proceed smoothly now. 🙂

Please notes that when the update finished, this file will be changed as well, so when you trying to update next time, your timeout will back to default set by WordPress developer. So, when you want to update next time, it is recommended to repeat this step, and in future version, this function may be changed as well, so it is preferable to don’t use the copy of the older version you have changed this time.

Well, I hope WordPress developer will add this to configuration, so we don’t need to change the files manually anymore. 🙂 Thanks for reading, hope it useful.

4 comments | Leave a comment

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.