PluginProbe
404 Solution / 4.3.3
404 Solution v4.3.3
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 / DatabaseRuntimeState.php

DatabaseRuntimeState.php in 404 Solution 4.3.3, at includes/database/DatabaseRuntimeState.php

88 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if (!defined('ABSPATH')) {
4 exit;
5 }
6
7 /**
8 * Database infrastructure state shared by DatabaseCore helpers.
9 *
10 * Capability probes are memoized in-process and persisted briefly through
11 * WordPress transients so a known host limitation is not rediscovered by
12 * every new PHP request.
13 */
14 final class ABJ_404_Solution_DatabaseRuntimeState {
15
16 /** @var int Cooldown when DB query quota is exceeded. */
17 const DB_QUOTA_COOLDOWN_SECONDS = 900;
18
19 /** @var int Cooldown when DB is read-only or storage is full. */
20 const DB_WRITE_BLOCK_COOLDOWN_SECONDS = 900;
21
22 /** @var string Cross-request flag for hosts that reject SET STATEMENT. */
23 const SET_STATEMENT_WRAPPER_UNSUPPORTED_TRANSIENT = 'abj404_set_statement_wrapper_unsupported';
24
25 /** @var int Re-probe SET STATEMENT support after one hour. */
26 const SET_STATEMENT_WRAPPER_UNSUPPORTED_TTL_SECONDS = 3600;
27
28 /** @var bool Whether MariaDB SET STATEMENT wrapper failed and should be skipped. */
29 private static $setStatementWrapperUnsupported = false;
30
31 /** @var bool Whether the persisted capability flag was checked this request. */
32 private static $setStatementWrapperPersistenceChecked = false;
33
34 /**
35 * Update request-local support state and persist confirmed rejection.
36 *
37 * Passing false resets only request-local memoization. The transient is
38 * deliberately left intact so the next request still honors the observed
39 * host capability until its short TTL expires.
40 *
41 * @return void
42 */
43 public static function setSetStatementWrapperUnsupported(bool $value): void {
44 self::$setStatementWrapperUnsupported = $value;
45 self::$setStatementWrapperPersistenceChecked = $value;
46 if ($value && function_exists('set_transient')) {
47 // allow-cache-empty: capability-probe result, not a fallible query result.
48 set_transient(
49 self::SET_STATEMENT_WRAPPER_UNSUPPORTED_TRANSIENT,
50 1,
51 self::SET_STATEMENT_WRAPPER_UNSUPPORTED_TTL_SECONDS
52 );
53 }
54 }
55
56 /** @return bool */
57 public static function isSetStatementWrapperUnsupported(): bool {
58 if (self::$setStatementWrapperUnsupported) {
59 return true;
60 }
61 if (self::$setStatementWrapperPersistenceChecked) {
62 return false;
63 }
64
65 self::$setStatementWrapperPersistenceChecked = true;
66 if (function_exists('get_transient')) {
67 $persisted = get_transient(self::SET_STATEMENT_WRAPPER_UNSUPPORTED_TRANSIENT);
68 self::$setStatementWrapperUnsupported = in_array($persisted, array(1, '1', true), true);
69 }
70 return self::$setStatementWrapperUnsupported;
71 }
72
73 /**
74 * Name the source the next timeout-capability read will consult.
75 *
76 * This exposes no cache value or key. It exists so query-preflight
77 * diagnostics can distinguish an in-process decision from a WordPress
78 * transient read that may invoke a third-party object-cache drop-in.
79 */
80 public static function setStatementWrapperCapabilitySource(): string {
81 if (self::$setStatementWrapperUnsupported
82 || self::$setStatementWrapperPersistenceChecked) {
83 return 'request_local';
84 }
85 return function_exists('get_transient') ? 'transient' : 'unavailable';
86 }
87 }
88