Created
July 11, 2016 12:17
-
-
Save rayrutjes/8ca8bedf9b3aab0552aa917b469a9023 to your computer and use it in GitHub Desktop.
Support curl timeout in milliseconds in WordPress.
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 adjust_curl_timeout( $handle, $r, $url ) { | |
if ( ! isset( $r['timeout'] ) ) { | |
return; | |
} | |
$timeout = $r['timeout']; | |
if( ! is_float( $timeout ) ) { | |
return; | |
} | |
$timeout = (int) ceil( $timeout * 1000 ); | |
curl_setopt( $handle, CURLOPT_CONNECTTIMEOUT_MS, $timeout ); | |
curl_setopt( $handle, CURLOPT_TIMEOUT_MS, $timeout ); | |
} | |
add_action( 'http_api_curl', 'adjust_curl_timeout', 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment