Created
August 21, 2020 17:57
-
-
Save kodie/5c5bc1c1de2c40d32e28daf30bc1226b to your computer and use it in GitHub Desktop.
Allows you to set a custom timeout for WordPress cURL requests
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 | |
// Set HTTP Request Timeout | |
add_filter('http_request_args', 'my_http_request_args', 100, 1); | |
function my_http_request_args($r) { | |
$r['timeout'] = 30; | |
return $r; | |
} | |
// Set HTTP Request Timeout | |
add_filter('http_request_timeout', 'my_custom_http_request_timeout', 101); | |
function my_custom_http_request_timeout($time_limit) { | |
return 30; | |
} | |
// Set WP HTTP API Timeout | |
add_action('http_api_curl', 'my_http_api_curl', 100, 1); | |
function my_http_api_curl($handle) { | |
curl_setopt($handle, CURLOPT_CONNECTTIMEOUT, 30); | |
curl_setopt($handle, CURLOPT_TIMEOUT, 30); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment