PluginProbe
ThinkRank AI SEO – AI SEO Plugin for WordPress: Schema, XML Sitemaps, Meta Tags, Search Console & Local SEO / trunk
ThinkRank AI SEO – AI SEO Plugin for WordPress: Schema, XML Sitemaps, Meta Tags, Search Console & Local SEO vtrunk
2.6.0 2.5.0 2.4.0 2.3.0 2.2.0 2.1.1 2.1.0 2.0.2 2.0.1 2.0.0 1.32.0 1.31.0 1.30.0 1.29.0 1.28.0 1.27.0 1.26.0 1.25.0 trunk 1.0.0 1.0.1 1.0.2 1.1.0 1.10.0 1.11.0 All 47 releases
thinkrank / includes / ai / traits / trait-request-timeout.php

trait-request-timeout.php in ThinkRank AI SEO – AI SEO Plugin for WordPress: Schema, XML Sitemaps, Meta Tags, Search Console & Local SEO trunk, at includes/ai/traits/trait-request-timeout.php

49 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Request-timeout classification for AI HTTP clients.
4 *
5 * @package ThinkRank\AI\Traits
6 */
7
8 declare(strict_types=1);
9
10 namespace ThinkRank\AI\Traits;
11
12 if (!defined('ABSPATH')) {
13 exit;
14 }
15
16 /**
17 * Shared timeout detection for the clients that own a request_with_retry() loop.
18 *
19 * OpenAI, Claude and Gemini each carried an identical copy of is_timeout_error();
20 * a change to how a timeout is recognised had to be made in three places or the
21 * retry behaviour would diverge between providers (issue #288). This trait is the
22 * single copy they all use.
23 */
24 trait Request_Timeout {
25
26 /**
27 * Whether a WP_Error from the WordPress HTTP API is a client-side timeout.
28 *
29 * A cURL timeout (error 28) surfaces as the 'http_request_failed' code with
30 * a message containing "Operation timed out" / "timed out". WP_Error codes
31 * are not a stable contract across HTTP transports, so match the message
32 * too, and treat ONLY a recognised timeout as non-retryable — any other
33 * network failure (DNS, connection refused, TLS) keeps the existing retry
34 * behaviour so this cannot make an unrelated transient failure worse.
35 *
36 * @param \WP_Error $error The error returned by wp_remote_request().
37 * @return bool True if the error represents a request timeout.
38 */
39 private function is_timeout_error(\WP_Error $error): bool {
40 foreach ((array) $error->get_error_messages() as $message) {
41 if (stripos((string) $message, 'timed out') !== false
42 || stripos((string) $message, 'timeout') !== false) {
43 return true;
44 }
45 }
46 return false;
47 }
48 }
49