PluginProbe
404 Solution / trunk
404 Solution vtrunk
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 / diagnostics / MalformedCheckpointEvidence.php

MalformedCheckpointEvidence.php in 404 Solution trunk, at includes/diagnostics/MalformedCheckpointEvidence.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 if (!defined('ABSPATH')) {
4 exit;
5 }
6
7 /**
8 * Selects bounded malformed fixed-sink lines for support evidence.
9 *
10 * Corrupt records cannot participate in request ranking because they have no
11 * readable request identity. They still prove that the durable sink was
12 * reached, so a small newest-first reserve keeps them without letting one
13 * unbounded line consume the support payload.
14 */
15 final class ABJ_404_Solution_MalformedCheckpointEvidence {
16
17 /** Keep the newest bounded corruption samples outside ordinary ranking. */
18 private const MAX_RESERVED_LINES = 4;
19
20 /** A corrupt line must never consume the bounded support payload by itself. */
21 private const MAX_RESERVED_LINE_BYTES = 1024;
22
23 private const TRUNCATION_SUFFIX = '...[malformed line truncated]';
24
25 /**
26 * @param array<int, string> $lines JSONL lines, oldest first.
27 * @return array<int, string>
28 */
29 public static function select(array $lines): array {
30 $selected = array();
31 foreach ($lines as $line) {
32 if (is_array(json_decode($line, true))) {
33 continue;
34 }
35 if (strlen($line) > self::MAX_RESERVED_LINE_BYTES) {
36 $prefixBytes = self::MAX_RESERVED_LINE_BYTES
37 - strlen(self::TRUNCATION_SUFFIX);
38 $line = substr($line, 0, max(0, $prefixBytes))
39 . self::TRUNCATION_SUFFIX;
40 }
41 $selected[] = $line;
42 if (count($selected) > self::MAX_RESERVED_LINES) {
43 array_shift($selected);
44 }
45 }
46 return $selected;
47 }
48 }
49