PluginProbe
Cache Warmer / 1.3.2
Cache Warmer v1.3.2
1.3.10 trunk 1.0.1 1.0.17 1.0.19 1.0.2 1.0.20 1.0.21 1.0.22 1.0.3 1.0.34 1.0.36 1.0.37 1.0.38 1.0.39 1.0.40 1.0.41 1.0.44 1.0.51 1.1.2 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 All 41 releases
cache-warmer / src / class-debug.php

class-debug.php in Cache Warmer 1.3.2, at src/class-debug.php

89 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Class for debug data.
4 *
5 * @package Cache-Warmer
6 */
7
8 namespace Cache_Warmer;
9
10 use Exception;
11
12 /**
13 * Debug class.
14 */
15 final class Debug {
16
17 /**
18 * Maybe returns the debug array.
19 *
20 * @return array Debug array.
21 *
22 * @throws Exception Exception.
23 */
24 public static function maybe_get_debug_array() {
25 return self::debug_mode_enabled()
26 &&
27 (
28 // Return only 1 / 10th (each 50s on average) due to the potentially big size.
29 self::debug_each_request() || 1 === wp_rand( 1, 10 )
30 )
31 ? self::get_debug_array() : [];
32 }
33
34 /**
35 * Returns the debug array.
36 *
37 * @return array Debug array.
38 *
39 * @throws Exception Exception.
40 */
41 public static function get_debug_array() {
42 $data = [
43 'current-server-ip-address' => Server_IP_Detection::get_current_server_ip(),
44 'last-processing-link' => Cache_Warmer::$options->get( 'last-processing-link' ),
45 'last-failed-to-retrieve-link' => Cache_Warmer::$options->get( 'last-failed-to-retrieve-link' ),
46 'last-retrieved-link' => Cache_Warmer::$options->get( 'last-retrieved-link' ),
47 ];
48
49 $options_to_inspect = [
50 'links-tree-leftovers',
51 'retrieved-links',
52 'failed-to-retrieve-links',
53 'unscheduled-links-tree-leftovers',
54 'unscheduled-retrieved-links',
55 'unscheduled-failed-to-retrieve-links',
56 ];
57
58 foreach ( $options_to_inspect as $option ) {
59 $option_name = "cache-warmer-$option";
60 $data[ $option ] = [
61 'fromObjectCache' => Cache_Warmer::$options->use_object_cache_for_option( $option_name ),
62 'value' => Cache_Warmer::$options->get( $option_name ),
63 'optionValue' => get_option( $option_name ),
64 'cacheValue' => wp_cache_get( $option_name ),
65 ];
66 }
67
68 return $data;
69 }
70
71 /**
72 * Check if the plugin debug mode is enabled.
73 *
74 * @return bool
75 */
76 private static function debug_mode_enabled() {
77 return isset( $_ENV['CACHE_WARMER_DEBUG'] ) && in_array( $_ENV['CACHE_WARMER_DEBUG'], [ 'true', '1', 'yes' ], true );
78 }
79
80 /**
81 * Check if needed to debug each request.
82 *
83 * @return bool
84 */
85 private static function debug_each_request() {
86 return isset( $_ENV['CACHE_WARMER_DEBUG_EACH_REQUEST'] ) && in_array( $_ENV['CACHE_WARMER_DEBUG_EACH_REQUEST'], [ 'true', '1', 'yes' ], true );
87 }
88 }
89