-
-
Save cyberwani/33d0262cc582d13711e7039a0305fedf to your computer and use it in GitHub Desktop.
Increase the curl timeout in WordPress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Copied from http://fatlabmusic.com/blog/2009/08/12/how-to-fix-wp-http-error-name-lookup-timed-out/ | |
adjustments to wp-includes/http.php timeout values to workaround slow server responses | |
*/ | |
/** | |
* Filters the arguments used in an HTTP request. | |
* | |
* @param array $parsed_args An array of HTTP request arguments. | |
* @param string $url The request URL. | |
*/ | |
function bal_http_request_args( $parsed_args, $url ) { | |
$parsed_args['timeout'] = 20; | |
return $parsed_args; | |
} | |
add_filter( 'http_request_args', 'bal_http_request_args', 100, 2 ); | |
/** | |
* Fires before the cURL request is executed. | |
* | |
* Cookies are not currently handled by the HTTP API. This action allows | |
* plugins to handle cookies themselves. | |
* | |
* @param resource $handle The cURL handle returned by curl_init() (passed by reference). | |
* @param array $parsed_args The HTTP request arguments. | |
* @param string $url The request URL. | |
*/ | |
function bal_http_api_curl( $handle, $parsed_args, $url ) { | |
curl_setopt( $handle, CURLOPT_CONNECTTIMEOUT, 20 ); | |
curl_setopt( $handle, CURLOPT_TIMEOUT, 20 ); | |
} | |
add_action( 'http_api_curl', 'bal_http_api_curl', 100, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment