PluginProbe
404 Solution / 4.3.0
404 Solution v4.3.0
4.3.5 4.3.4 4.3.3 4.3.2 4.3.1 4.3.0 4.2.0 4.1.19 4.1.18 4.1.17 4.1.16 4.1.15 4.1.13 4.1.12 4.1.11 4.1.10 4.1.9 4.1.8 4.1.7 4.1.6 4.1.5 4.1.4 4.1.3 trunk 2.30.0 All 109 releases
404-solution / includes / database / DatabaseConnectivityErrorTaxonomy.php

DatabaseConnectivityErrorTaxonomy.php in 404 Solution 4.3.0, at includes/database/DatabaseConnectivityErrorTaxonomy.php

97 lines 3.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Pure database connectivity error taxonomy.
4 *
5 * Owns string-based classification of transport-level failures: network
6 * connection drops, query-execution timeouts, packet size limits, and
7 * deadlock / lock-wait contention. These are the error classes the retry
8 * and staged-build "resumable kill" policies act on.
9 *
10 * No side effects: callers reuse the matchers without inheriting recovery
11 * behavior.
12 */
13
14 if (!defined('ABSPATH')) {
15 exit;
16 }
17
18 // allow-no-test-found: covered through DatabaseInfrastructureErrorTaxonomy facade by tests/ErrorClassifierTest.php and tests/StagedBuildHostQuirksTest.php
19 class ABJ_404_Solution_DatabaseConnectivityErrorTaxonomy {
20
21 /** @var ABJ_404_Solution_Functions */
22 private $f;
23
24 /**
25 * @param ABJ_404_Solution_Functions $functions
26 */
27 public function __construct($functions) {
28 $this->f = $functions;
29 }
30
31 /** @param string|null $errorText @return bool */
32 public function isTransientConnectionError(?string $errorText): bool {
33 $errorText = $errorText ?? '';
34 if ($errorText === '') {
35 return false;
36 }
37 $lower = strtolower($errorText);
38 $transientMarkers = array(
39 'server has gone away',
40 'lost connection to mysql server during query',
41 'error while sending query packet',
42 'packets out of order',
43 'connection was killed',
44 );
45 foreach ($transientMarkers as $marker) {
46 if ($this->f->strpos($lower, $marker) !== false) {
47 return true;
48 }
49 }
50 foreach (array('2006', '2013') as $code) {
51 if ($this->f->strpos($lower, '[' . $code . ']') !== false
52 || $this->f->strpos($lower, '(' . $code . ')') !== false
53 || $this->f->strpos($lower, 'errno ' . $code) !== false
54 || $this->f->strpos($lower, 'errno: ' . $code) !== false
55 || $this->f->strpos($lower, 'error: ' . $code . ' ') !== false
56 || $this->f->strpos($lower, 'error ' . $code . ':') !== false) {
57 return true;
58 }
59 }
60 return false;
61 }
62
63 /** @param string $errorText @return bool */
64 public function isQueryTimeoutError(string $errorText): bool {
65 if ($errorText === '') {
66 return false;
67 }
68 return (strpos($errorText, '3024') !== false ||
69 strpos($errorText, '1969') !== false ||
70 stripos($errorText, 'max_execution_time') !== false ||
71 stripos($errorText, 'max_statement_time') !== false);
72 }
73
74 /** @param string $errorText @return bool */
75 public function isPacketTooLarge(string $errorText): bool {
76 if ($errorText === '') {
77 return false;
78 }
79 $lower = strtolower($errorText);
80 return ($this->f->strpos($lower, 'max_allowed_packet') !== false ||
81 $this->f->strpos($lower, 'got a packet bigger') !== false ||
82 $this->f->strpos($lower, '1153') !== false);
83 }
84
85 /** @param string $errorText @return bool */
86 public function isDeadlockOrLockTimeoutError(string $errorText): bool {
87 if ($errorText === '') {
88 return false;
89 }
90 $lower = strtolower($errorText);
91 return ($this->f->strpos($lower, 'deadlock found') !== false ||
92 $this->f->strpos($lower, 'lock wait timeout exceeded') !== false ||
93 $this->f->strpos($lower, 'error 1213') !== false ||
94 $this->f->strpos($lower, 'error 1205') !== false);
95 }
96 }
97