PluginProbe ʕ •ᴥ•ʔ
LiteSpeed Cache / 7.5.0.1
LiteSpeed Cache v7.5.0.1
trunk 1.0.15 1.9.1.1 2.9.9.2 3.6.4 4.6 5.7.0.1 6.5.4 7.0.0.1 7.0.1 7.1 7.2 7.3 7.3.0.1 7.4 7.5 7.5.0.1 7.6 7.6.1 7.6.2 7.7 7.8 7.8.0.1 7.8.1
litespeed-cache / src / health.cls.php
litespeed-cache / src Last commit date
cdn 8 months ago data_structure 8 months ago activation.cls.php 8 months ago admin-display.cls.php 8 months ago admin-settings.cls.php 8 months ago admin.cls.php 8 months ago api.cls.php 8 months ago avatar.cls.php 8 months ago base.cls.php 8 months ago cdn.cls.php 8 months ago cloud.cls.php 8 months ago conf.cls.php 8 months ago control.cls.php 8 months ago core.cls.php 8 months ago crawler-map.cls.php 8 months ago crawler.cls.php 8 months ago css.cls.php 8 months ago data.cls.php 8 months ago data.upgrade.func.php 8 months ago db-optm.cls.php 8 months ago debug2.cls.php 8 months ago doc.cls.php 8 months ago error.cls.php 8 months ago esi.cls.php 8 months ago file.cls.php 8 months ago gui.cls.php 8 months ago health.cls.php 8 months ago htaccess.cls.php 8 months ago img-optm.cls.php 8 months ago import.cls.php 8 months ago import.preset.cls.php 8 months ago lang.cls.php 8 months ago localization.cls.php 8 months ago media.cls.php 8 months ago metabox.cls.php 8 months ago object-cache-wp.cls.php 8 months ago object-cache.cls.php 8 months ago object.lib.php 8 months ago optimize.cls.php 8 months ago optimizer.cls.php 8 months ago placeholder.cls.php 8 months ago purge.cls.php 8 months ago report.cls.php 8 months ago rest.cls.php 8 months ago root.cls.php 8 months ago router.cls.php 8 months ago str.cls.php 8 months ago tag.cls.php 8 months ago task.cls.php 8 months ago tool.cls.php 8 months ago ucss.cls.php 8 months ago utility.cls.php 8 months ago vary.cls.php 8 months ago vpi.cls.php 8 months ago
health.cls.php
128 lines
1 <?php
2 // phpcs:ignoreFile
3 /**
4 * The page health
5 *
6 * @since 3.0
7 * @package LiteSpeed
8 */
9 namespace LiteSpeed;
10
11 defined('WPINC') || exit();
12
13 class Health extends Base {
14
15 const TYPE_SPEED = 'speed';
16 const TYPE_SCORE = 'score';
17
18 protected $_summary;
19
20 /**
21 * Init
22 *
23 * @since 3.0
24 */
25 public function __construct() {
26 $this->_summary = self::get_summary();
27 }
28
29 /**
30 * Test latest speed
31 *
32 * @since 3.0
33 */
34 private function _ping( $type ) {
35 $data = array( 'action' => $type );
36
37 $json = Cloud::post(Cloud::SVC_HEALTH, $data, 600);
38
39 if (empty($json['data']['before']) || empty($json['data']['after'])) {
40 Debug2::debug('[Health] ❌ no data');
41 return false;
42 }
43
44 $this->_summary[$type . '.before'] = $json['data']['before'];
45 $this->_summary[$type . '.after'] = $json['data']['after'];
46
47 self::save_summary();
48
49 Debug2::debug('[Health] saved result');
50 }
51
52 /**
53 * Generate scores
54 *
55 * @since 3.0
56 */
57 public function scores() {
58 $speed_before = $speed_after = $speed_improved = 0;
59 if (!empty($this->_summary['speed.before']) && !empty($this->_summary['speed.after'])) {
60 // Format loading time
61 $speed_before = $this->_summary['speed.before'] / 1000;
62 if ($speed_before < 0.01) {
63 $speed_before = 0.01;
64 }
65 $speed_before = number_format($speed_before, 2);
66
67 $speed_after = $this->_summary['speed.after'] / 1000;
68 if ($speed_after < 0.01) {
69 $speed_after = number_format($speed_after, 3);
70 } else {
71 $speed_after = number_format($speed_after, 2);
72 }
73
74 $speed_improved = (($this->_summary['speed.before'] - $this->_summary['speed.after']) * 100) / $this->_summary['speed.before'];
75 if ($speed_improved > 99) {
76 $speed_improved = number_format($speed_improved, 2);
77 } else {
78 $speed_improved = number_format($speed_improved);
79 }
80 }
81
82 $score_before = $score_after = $score_improved = 0;
83 if (!empty($this->_summary['score.before']) && !empty($this->_summary['score.after'])) {
84 $score_before = $this->_summary['score.before'];
85 $score_after = $this->_summary['score.after'];
86
87 // Format Score
88 $score_improved = (($score_after - $score_before) * 100) / $score_after;
89 if ($score_improved > 99) {
90 $score_improved = number_format($score_improved, 2);
91 } else {
92 $score_improved = number_format($score_improved);
93 }
94 }
95
96 return array(
97 'speed_before' => $speed_before,
98 'speed_after' => $speed_after,
99 'speed_improved' => $speed_improved,
100 'score_before' => $score_before,
101 'score_after' => $score_after,
102 'score_improved' => $score_improved,
103 );
104 }
105
106 /**
107 * Handle all request actions from main cls
108 *
109 * @since 3.0
110 * @access public
111 */
112 public function handler() {
113 $type = Router::verify_type();
114
115 switch ($type) {
116 case self::TYPE_SPEED:
117 case self::TYPE_SCORE:
118 $this->_ping($type);
119 break;
120
121 default:
122 break;
123 }
124
125 Admin::redirect();
126 }
127 }
128