class-telemetry.php

Telemetry Class

Source includes/Insight/class-telemetry.php7 min readPart of Performance Optimisation

includes/Insight/class-telemetry.php

Telemetry Class

Namespace: PerformanceOptimise\\Inc · Lines: 1197

Class Telemetry

Class Telemetry

Source: includes/Insight/class-telemetry.php, line 34

class Telemetry

Tags: @since 1.5.0

Constants

ConstantVisibilityValueLine
AUDIT_SALT_KEYprivate\'wppo_audit_salt\'42
MAX_REDIRECT_HOPSprivate253

publicstatic scan()

public static function scan(string $url, string=\'manual\' $scan_type, bool=false $force): array|\\WP_Error

Scan a URL and return all performance metrics.

ParameterTypeDefaultDescription
$urlstring—The URL to scan.
$scan_typestring=\'manual\'—Either \’manual\’ or \’scheduled\’.
$forcebool=false—Whether to bypass cache.

Return: array|\\WP_Error — Associative array of metrics, or WP_Error on failure.

Tags: @since 1.5.0

Source: includes/Insight/class-telemetry.php, line 75

publicstatic get_cached_result()

public static function get_cached_result(string $url)

Read a cached telemetry result without executing a scan.

ParameterTypeDefaultDescription
$urlstring—Scanned URL.

Return: mixed — Cached telemetry payload, or false when absent.

Tags: @since NEXT

Source: includes/Insight/class-telemetry.php, line 240

privatestatic read_cached_audit()

private static function read_cached_audit(string $url, string $lookup_key, bool $has_salted): mixed

Read an audit cache entry for scan and query callers.

ParameterTypeDefaultDescription
$urlstring—Scanned URL.
$lookup_keystring—Cache key to read.
$has_saltedbool—Whether the salted cache layer is available.

Return: mixed — Cached telemetry payload, or false when absent.

Tags: @since NEXT

Source: includes/Insight/class-telemetry.php, line 259

protectedstatic execute_curl()

protected static function execute_curl(string $url): array

Execute a single cURL request without following redirects.

ParameterTypeDefaultDescription
$urlstring—URL to request. string|false $raw_response Raw response (headers + body), or false on transport failure. array $info curl_getinfo() transfer info. int $error curl_errno() value (0 = success).

Return: array — {.

Tags: @since 2.2.0

Source: includes/Insight/class-telemetry.php, line 290

privatestatic parse_header_block()

private static function parse_header_block(string $header_raw): array

Parse raw response headers into a lowercase-keyed array.

ParameterTypeDefaultDescription
$header_rawstring—Raw header text (everything before the body).

Return: array — Lowercase header name => value map.

Tags: @since 2.2.0

Source: includes/Insight/class-telemetry.php, line 346

privatestatic resolve_redirect()

private static function resolve_redirect(string $location, string $current_url): string|false

Resolve and validate a redirect Location against the current URL.

ParameterTypeDefaultDescription
$locationstring—Raw Location header value.
$current_urlstring—URL of the response that sent the Location.

Return: string|false — Absolute validated URL, or false when the hop is not allowed.

Tags: @since 2.2.0

Source: includes/Insight/class-telemetry.php, line 374

protectedstatic fetch_via_curl()

protected static function fetch_via_curl(string $url): array|\\WP_Error|null

Fetch a page via cURL, manually following validated redirects.

ParameterTypeDefaultDescription
$urlstring—Validated scan URL. string $body Response body. array $headers Lowercase response headers from the final hop. array $timings DNS/connect/SSL/TTFB timings in milliseconds. float $load_time Total load time of the final hop in seconds.

Return: array|\\WP_Error|null — { Success payload on a 200 response, WP_Error on an unsafe hop or exceeded hop limit, or null when the wp_remote_get() fallback should be used instead.

Tags: @since 2.2.0

Source: includes/Insight/class-telemetry.php, line 403

protectedstatic fetch_via_wp_remote()

protected static function fetch_via_wp_remote(string $url): array|\\WP_Error

Fetch a page via wp_remote_get(), manually following validated redirects.

ParameterTypeDefaultDescription
$urlstring—Validated scan URL.

Return: array|\\WP_Error — Success payload, or WP_Error on failure/unsafe hop/hop limit.

Tags: @since 2.2.0

Source: includes/Insight/class-telemetry.php, line 478

privatestatic parse_resources()

private static function parse_resources(string $html): array

Parse CSS, JS, and image resources from an HTML string.

ParameterTypeDefaultDescription
$htmlstring—The raw HTML body to parse. string[] $css Array of stylesheet href values. string[] $js Array of script src values. array[] $images Array of image data with \’src\’, \’alt\’, and \’lazy\’ keys.

Return: array — {.

Tags: @since 1.5.0

Source: includes/Insight/class-telemetry.php, line 576

privatestatic calculate_sizes()

private static function calculate_sizes(array $resources): array

Calculate asset sizes using local filesystem paths.

ParameterTypeDefaultDescription
$resourcesarray—Parsed resources from parse_resources(). int $css Total CSS size in bytes. int $js Total JS size in bytes. int $images Total image size in bytes.

Return: array — {.

Tags: @since 1.5.0

Source: includes/Insight/class-telemetry.php, line 724

privatestatic check_https()

private static function check_https(string $url): bool

Check whether the URL uses HTTPS.

ParameterTypeDefaultDescription
$urlstring—The URL to check.

Return: bool — True if HTTPS, false otherwise.

Tags: @since 1.5.0

Source: includes/Insight/class-telemetry.php, line 829

privatestatic check_compression()

private static function check_compression($headers): bool

Check whether Gzip, Brotli, or Deflate compression is active.

ParameterTypeDefaultDescription
$headersobject|array—Response headers.

Return: bool — True if compressed, false otherwise.

Tags: @since 1.5.0

Source: includes/Insight/class-telemetry.php, line 843

privatestatic get_compression_type()

private static function get_compression_type($headers): string

Retrieve the raw Content-Encoding header value.

ParameterTypeDefaultDescription
$headersobject|array—Response headers.

Return: string — The raw header value, or \’none\’ if not set.

Tags: @since 1.6.0

Source: includes/Insight/class-telemetry.php, line 869

privatestatic check_cache_control()

private static function check_cache_control($headers): bool

Check whether Cache-Control headers are set for at least one week.

ParameterTypeDefaultDescription
$headersobject|array—Response headers.

Return: bool — True if max-age >= 604800, false otherwise.

Tags: @since 1.5.0

Source: includes/Insight/class-telemetry.php, line 885

privatestatic get_cache_control()

private static function get_cache_control($headers): string

Retrieve the raw Cache-Control header value.

ParameterTypeDefaultDescription
$headersobject|array—Response headers.

Return: string — The raw header value, or \’none\’ if not set.

Tags: @since 1.6.0

Source: includes/Insight/class-telemetry.php, line 899

privatestatic get_header_value()

private static function get_header_value($headers, string $name): string

Helper to retrieve a header value from various header structures.

ParameterTypeDefaultDescription
$headersobject|array—Response headers.
$namestring—Header name in lowercase (e.g. \’content-encoding\’).

Return: string — Header value or empty string if not found.

Tags: @since 1.6.0

Source: includes/Insight/class-telemetry.php, line 916

privatestatic check_robots_txt()

private static function check_robots_txt(string $url): bool

Check whether a robots.txt file exists at the given URL\’s root.

ParameterTypeDefaultDescription
$urlstring—The page URL whose host to check.

Return: bool — True if robots.txt returns HTTP 200, false otherwise.

Tags: @since 1.5.0

Source: includes/Insight/class-telemetry.php, line 940

privatestatic check_modern_images()

private static function check_modern_images(array $images): float

Check whether any images use modern formats (WebP or AVIF).

ParameterTypeDefaultDescription
$imagesarray—Array of image data from parse_resources().

Return: float — Percentage of images using modern formats (0-100).

Tags: @since 1.5.0

Source: includes/Insight/class-telemetry.php, line 996

privatestatic check_alt_attributes()

private static function check_alt_attributes(array $images): bool

Check whether all images have non-empty alt attributes.

ParameterTypeDefaultDescription
$imagesarray—Array of image data from parse_resources().

Return: bool — True if all images have alt text, false otherwise.

Tags: @since 1.5.0 · @since 2.0.0 Empty-string alt also fails the check.

Source: includes/Insight/class-telemetry.php, line 1027

publicstatic invalidate_audit_cache()

public static function invalidate_audit_cache(): void

Invalidate the audit cache salt so future scans bypass stale cached data.

Return: void.

Tags: @since 2.0.0

Source: includes/Insight/class-telemetry.php, line 1050

publicstatic register_transient_key()

public static function register_transient_key(string $key): void

Register a transient key in the master index for safe bulk deletion.

ParameterTypeDefaultDescription
$keystring—The transient key to register.

Return: void.

Tags: @since 1.5.0 · @since 2.0.0 Added re-read-before-write merge with bounded retry. · @since 2.0.0 Skip the verify re-read on the first attempt when the merge observed no concurrent changes (2 reads instead of 3 on the common no-contention path).

Source: includes/Insight/class-telemetry.php, line 1101

privatestatic read_transient_index()

private static function read_transient_index(): array

Read and normalize the transient index option.

Return: array<string, — int>.

Tags: @since 2.0.0

Source: includes/Insight/class-telemetry.php, line 1165

privatestatic prune_transient_index()

private static function prune_transient_index(array $index, int $now): array

Prune expired entries and cap the transient index size.

ParameterTypeDefaultDescription
$indexarray——
$nowint—Current timestamp.

Return: array<string, — int> Pruned, capped index.

Tags: @since 2.0.0

Source: includes/Insight/class-telemetry.php, line 1178

Hooks

Hooks referenced in includes/Insight/class-telemetry.php:

HookTypeLineNotes
wppo_telemetry_verify_sslfilter313—
wppo_telemetry_verify_sslfilter489—
wppo_telemetry_allow_remote_headfilter759—
wppo_telemetry_verify_sslfilter967—