Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rayrutjes/8ca8bedf9b3aab0552aa917b469a9023 to your computer and use it in GitHub Desktop.
Save rayrutjes/8ca8bedf9b3aab0552aa917b469a9023 to your computer and use it in GitHub Desktop.
Support curl timeout in milliseconds in WordPress.
<?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