Created
February 26, 2012 23:15
-
-
Save goblindegook/1919587 to your computer and use it in GitHub Desktop.
Adjust WordPress HTTP request timeout
This file contains hidden or 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 | |
function my_http_request_args ( $r ) | |
{ | |
$r['timeout'] = 15; # new timeout | |
return $r; | |
} | |
add_filter( 'http_request_args', 'my_http_request_args', 100, 1 ); | |
function my_http_api_curl ( $handle ) | |
{ | |
curl_setopt( $handle, CURLOPT_CONNECTTIMEOUT, 15 ); # new timeout | |
curl_setopt( $handle, CURLOPT_TIMEOUT, 15 ); # new timeout | |
} | |
add_action( 'http_api_curl', 'my_http_api_curl', 100, 1 ); | |
?> |
@raamdev code has incorrectly spelt function name, "__extend_http_reqest_timeout" is missing the "u" in "request".
Correct snippet is:
<?php
/**
* Extend http timeout duration to 15 seconds
*
* @param int $timeout The timeout duration in seconds. Default is 5.
*
* @return int The filtered timeout duration in seconds.
*/
function __extend_http_request_timeout( $timeout ) {
return 15; // seconds
}
add_filter( 'http_request_timeout', '__extend_http_request_timeout' );
@AbeCole thanks for catching that! I updated my comment.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The new way of doing this using the
http_request_timeout
filter: