Some people have a hard time updating WordPress because of a slow server or internet connection.
When that happens you are likely to see this error in your dashboard
‘An Unexpected HTTP Error occurred during the API request’
The function that retrieves the data files for an update is called wp_remote_get and it controls a lot of other things not just updates.
The WordPress HTTP API includes a number of functions that allow WordPress to connect to outside servers and retrieve data. The API was created to allow easy access to PHP functions not only for Core WordPress developers but also for plugin and end users to use in their code.
wp_remote_get() – Retrieves a URL using the GET HTTP method.
wp_remote_post() – Retrieves a URL using the POST HTTP method.
wp_remote_head() – Retrieves a URL using the HEAD HTTP method.
wp_remote_request() – Retrieves a URL using either the default GET or custom.
Since the update process uses wp_remote_get this is the function that you want to adjust.
Normally you should not edit core WordPress files because they will be overwritten when you perform an update but in this case it could be important to allow your install to work correctly. Remember to log in an outside text file what you have changed for later reference.
The Default Timeout is 5 seconds but if you are seeing the error above when you try to update you can alter a line of code in your core file.
Open folder and file wp-includes/http.php and go to line 223
* Send a HTTP request to a URI.
‘timeout’ => apply_filters( ‘http_request_timeout’, 5),
Adjust the timeout to a longer period of 30 or 60 seconds which should cure the problem. If it does not then you may have a different problem not related to getting the request from the WordPress update server such as a bad plugin that is altering this or other settings.
In this case you should download a copy of wordpress and upload it to your server following the manual install instructions. then manually run the update process to make changes.
Note the wp_remote_get function is used by other processes in WordPress like getting information about trackbacks . Extending the time if you see the initial error should solve your problems.