Does WordPress expose whether a timed-out HTTP API request was processed remotely?
0 reputation · 11 Aug 2022, 02:02 UTC
0 reputation · 11 Aug 2022, 02:02 UTC
Determine whether a WordPress caller can safely retry an outbound request after wp_remote_get() or wp_remote_post() returns a timeout WP_Error, without risking duplicate processing at the remote service.
Assuming current WordPress core HTTP API behavior, the timeout argument is transport-specific and core provides no unified cancellation token for an in-flight request. A local timeout does not indicate whether the remote server never received the request or already processed it but did not reply before the timeout. cURL-backed requests commonly surface error code 28, while the streams fallback may enforce timeouts differently depending on PHP configuration. Core does not normalize connect timeouts against remote response timeouts, and PHP max_execution_time or reverse-proxy limits can fail independently of the HTTP API argument.
No. WordPress core does not expose a reliable signal that distinguishes "request not received" from "request processed but no reply before the local timeout." When wp_remote_get() or wp_remote_post() returns a timeout WP_Error, the caller cannot determine from core data alone whether the remote service processed the request.
A timeout means the WordPress HTTP client stopped waiting for a response. It does not mean the request was never transmitted. The remote server may have received and acted on the request before the client-side timeout fired, with only the reply lost or delayed.
| Item | Behavior |
|---|---|
| Return value on timeout | WP_Error, typically with code http_request_failed |
| cURL transport | Typically surfaces cURL error code 28 (operation timed out) |
| Streams fallback | Enforces timeouts differently depending on PHP configuration; error codes and context may differ |
| Timeout normalization | Core does not normalize connect timeouts against read or response timeouts |
| External limits | PHP max_execution_time and reverse-proxy limits can fail independently of the HTTP API timeout argument |
| Remote completion signal | No core filter or WP_Error data field confirms that the remote side completed the request |
These describe general WordPress HTTP API behavior. Specific error codes and timing depend on the installed WordPress version, active transport, and server environment, so version-specific details should be reviewed in your deployment.
get_error_code() for http_request_failed and get_error_data() for transport-specific data such as cURL error 28. Confirm there is no remote-completion field.Whether the remote service supports idempotency keys or exposes a state-check endpoint. This detail changes the recommendation: with idempotency support, a retry can be safe; without it, you must verify remote state before retrying.
$response = wp_remote_get( $url, [ 'timeout' => 5 ] );
if ( is_wp_error( $response ) ) {
echo $response->get_error_code();
var_dump( $response->get_error_data() );
}
To confirm the gap, test against a local endpoint that logs request receipt, then sleeps longer than the timeout argument. WordPress should still return a timeout even though the remote endpoint logged the request.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.