Last active
March 2, 2025 11:37
-
-
Save mehrshaddarzi/30f83b8e77c854e8a8f6c3d41e656587 to your computer and use it in GitHub Desktop.
WordPress 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 | |
add_filter('http_request_args', 'bal_http_request_args', 100, 1); | |
function bal_http_request_args($r) //called on line 237 | |
{ | |
$r['timeout'] = 15; | |
return $r; | |
} | |
add_action('http_api_curl', 'bal_http_api_curl', 100, 1); | |
function bal_http_api_curl($handle) //called on line 1315 | |
{ | |
curl_setopt( $handle, CURLOPT_CONNECTTIMEOUT, 15 ); | |
curl_setopt( $handle, CURLOPT_TIMEOUT, 15 ); | |
} | |
// Add To wp-config.php | |
ini_set( 'default_socket_timeout', 300 ); | |
// Setting a custom timeout value for cURL. Using a high value for priority to ensure the function runs after any other added to the same action hook. | |
add_action('http_api_curl', 'wcpe_curl_timeout', 9999, 1); | |
function wcpe_curl_timeout($handle){ | |
curl_setopt($handle, CURLOPT_CONNECTTIMEOUT, 12); | |
curl_setopt($handle, CURLOPT_TIMEOUT, 12); | |
} | |
// Setting custom timeout for the HTTP request | |
add_filter('http_request_timeout', 'wcpe_http_request_timeout', 9999); | |
function wcpe_http_request_timeout($timeout_value){ | |
return 12; | |
} | |
// Setting custom timeout in HTTP request args | |
add_filter('http_request_args', 'wcpe_http_request_args', 9999, 1); | |
function wcpe_http_request_args($r){ | |
$r['timeout'] = 12; | |
return $r; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment