Changeset 3347790
- Timestamp:
- 08/21/2025 12:17:22 AM (7 months ago)
- Location:
- dynamic-front-end-heartbeat-control
- Files:
-
- 4 edited
-
tags/1.2.99/defibrillator/unclogger.php (modified) (2 diffs)
-
tags/1.2.99/engine/server-load.php (modified) (3 diffs)
-
trunk/defibrillator/unclogger.php (modified) (2 diffs)
-
trunk/engine/server-load.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
dynamic-front-end-heartbeat-control/tags/1.2.99/defibrillator/unclogger.php
r3320647 r3347790 3 3 4 4 defined('ABSPATH') or die(); 5 5 6 require_once plugin_dir_path(__FILE__) . 'unclogger-db.php'; 6 7 require_once plugin_dir_path(__FILE__) . 'db-health.php'; 7 8 8 class DfehcUnclogger {9 9 class DfehcUnclogger 10 { 10 11 protected $db; 11 12 protected $config; 12 13 13 14 protected $default_settings = [ 14 'auto_cleanup' => false,15 'auto_cleanup' => false, 15 16 'post_revision_limit' => 20, 16 17 ]; 17 18 18 public function __construct() { 19 if (defined('WP_CLI') && WP_CLI && file_exists(self::get_plugin_path() . 'defibrillator/cli-helper.php')) { 20 require_once(self::get_plugin_path() . 'defibrillator/cli-helper.php'); 19 public function __construct() 20 { 21 if (defined('WP_CLI') && WP_CLI) { 22 $base = rtrim(self::get_plugin_path(), '/\\'); 23 $cli = $base . '/cli-helper.php'; 24 25 if (!is_file($cli)) { 26 $cli = $base . '/defibrillator/cli-helper.php'; 27 } 28 29 if (is_file($cli)) { 30 require_once $cli; 31 } 21 32 } 22 33 … … 25 36 $this->set_default_settings(); 26 37 27 load_plugin_textdomain('dynamic-front-end-heartbeat-control', false, dirname(plugin_basename(__FILE__)) . '/languages'); 38 load_plugin_textdomain( 39 'dynamic-front-end-heartbeat-control', 40 false, 41 dirname(plugin_basename(__FILE__)) . '/languages' 42 ); 28 43 29 44 add_action('rest_api_init', [$this, 'register_rest_routes']); 30 45 } 31 46 32 public static function get_plugin_path() { 47 public static function get_plugin_path() 48 { 33 49 return plugin_dir_path(__FILE__); 34 50 } 35 51 36 public function set_default_settings() { 52 public function set_default_settings() 53 { 37 54 if (!get_option('dfehc_unclogger_settings')) { 38 55 update_option('dfehc_unclogger_settings', $this->default_settings, true); 39 56 } 40 57 } 41 42 58 public function get_settings() { 43 59 return get_option('dfehc_unclogger_settings', $this->default_settings); -
dynamic-front-end-heartbeat-control/tags/1.2.99/engine/server-load.php
r3320647 r3347790 235 235 add_action('wp_ajax_nopriv_get_server_load', 'dfehc_get_server_load_ajax_handler'); 236 236 237 function dfehc_get_server_load_persistent(): float 238 { 237 function dfehc_get_server_load_persistent(): float { 239 238 static $cached = null; 240 239 if ($cached !== null) { 241 240 return $cached; 242 241 } 242 243 243 ['client' => $client, 'type' => $type] = _dfehc_get_cache_client(); 244 244 $val = false; 245 245 246 if ($client) { 246 247 try { 247 248 $val = $client->get(DFEHC_SERVER_LOAD_CACHE_KEY); 248 249 } catch (Throwable $e) { 249 trigger_error('DFEHC cache read error: ' . $e->getMessage(), E_USER_WARNING); 250 } 251 } 250 if (defined('WP_DEBUG') && WP_DEBUG) { 251 trigger_error('DFEHC cache read error: ' . $e->getMessage(), E_USER_WARNING); 252 } 253 } 254 } 255 252 256 if ($val !== false) { 253 257 return $cached = (float) $val; 254 258 } 259 255 260 $fresh = dfehc_get_server_load(); 256 261 dfehc_cache_server_load($fresh); … … 258 263 } 259 264 260 function dfehc_register_minute_schedule(array $schedules): array 261 { 265 add_filter('cron_schedules', static function (array $schedules): array { 262 266 if (!isset($schedules['dfehc_minute'])) { 263 267 $schedules['dfehc_minute'] = [ … … 267 271 } 268 272 return $schedules; 269 } 270 add_filter('cron_schedules', 'dfehc_register_minute_schedule'); 271 272 if (apply_filters('dfehc_enable_load_logging', true)) { 273 }, 5); 274 275 $__dfehc_schedule = static function (): void { 276 if (!apply_filters('dfehc_enable_load_logging', true)) { 277 return; 278 } 273 279 if (!wp_next_scheduled('dfehc_log_server_load_hook')) { 274 $start = time() - (time() % 60) + 60; 275 wp_schedule_event($start, 'dfehc_minute', 'dfehc_log_server_load_hook'); 276 } 277 } 280 try { 281 $start = time() - (time() % 60) + 60; 282 wp_schedule_event($start, 'dfehc_minute', 'dfehc_log_server_load_hook'); 283 } catch (Throwable $e) { 284 if (defined('WP_DEBUG') && WP_DEBUG) { 285 trigger_error('DFEHC scheduling error: ' . $e->getMessage(), E_USER_WARNING); 286 } 287 } 288 } 289 }; 290 291 register_activation_hook(__FILE__, $__dfehc_schedule); 292 293 add_action('init', static function () use ($__dfehc_schedule): void { 294 $__dfehc_schedule(); 295 if (wp_next_scheduled('dfehc_log_server_load_hook')) { 296 remove_action('init', __FUNCTION__, 1); 297 } 298 }, 1); -
dynamic-front-end-heartbeat-control/trunk/defibrillator/unclogger.php
r3310561 r3347790 3 3 4 4 defined('ABSPATH') or die(); 5 5 6 require_once plugin_dir_path(__FILE__) . 'unclogger-db.php'; 6 7 require_once plugin_dir_path(__FILE__) . 'db-health.php'; 7 8 8 class DfehcUnclogger {9 9 class DfehcUnclogger 10 { 10 11 protected $db; 11 12 protected $config; 12 13 13 14 protected $default_settings = [ 14 'auto_cleanup' => false,15 'auto_cleanup' => false, 15 16 'post_revision_limit' => 20, 16 17 ]; 17 18 18 public function __construct() { 19 if (defined('WP_CLI') && WP_CLI && file_exists(self::get_plugin_path() . 'defibrillator/cli-helper.php')) { 20 require_once(self::get_plugin_path() . 'defibrillator/cli-helper.php'); 19 public function __construct() 20 { 21 if (defined('WP_CLI') && WP_CLI) { 22 $base = rtrim(self::get_plugin_path(), '/\\'); 23 $cli = $base . '/cli-helper.php'; 24 25 if (!is_file($cli)) { 26 $cli = $base . '/defibrillator/cli-helper.php'; 27 } 28 29 if (is_file($cli)) { 30 require_once $cli; 31 } 21 32 } 22 33 … … 25 36 $this->set_default_settings(); 26 37 27 load_plugin_textdomain('dynamic-front-end-heartbeat-control', false, dirname(plugin_basename(__FILE__)) . '/languages'); 38 load_plugin_textdomain( 39 'dynamic-front-end-heartbeat-control', 40 false, 41 dirname(plugin_basename(__FILE__)) . '/languages' 42 ); 28 43 29 44 add_action('rest_api_init', [$this, 'register_rest_routes']); 30 45 } 31 46 32 public static function get_plugin_path() { 47 public static function get_plugin_path() 48 { 33 49 return plugin_dir_path(__FILE__); 34 50 } 35 51 36 public function set_default_settings() { 52 public function set_default_settings() 53 { 37 54 if (!get_option('dfehc_unclogger_settings')) { 38 55 update_option('dfehc_unclogger_settings', $this->default_settings, true); 39 56 } 40 57 } 41 42 58 public function get_settings() { 43 59 return get_option('dfehc_unclogger_settings', $this->default_settings); -
dynamic-front-end-heartbeat-control/trunk/engine/server-load.php
r3320647 r3347790 235 235 add_action('wp_ajax_nopriv_get_server_load', 'dfehc_get_server_load_ajax_handler'); 236 236 237 function dfehc_get_server_load_persistent(): float 238 { 237 function dfehc_get_server_load_persistent(): float { 239 238 static $cached = null; 240 239 if ($cached !== null) { 241 240 return $cached; 242 241 } 242 243 243 ['client' => $client, 'type' => $type] = _dfehc_get_cache_client(); 244 244 $val = false; 245 245 246 if ($client) { 246 247 try { 247 248 $val = $client->get(DFEHC_SERVER_LOAD_CACHE_KEY); 248 249 } catch (Throwable $e) { 249 trigger_error('DFEHC cache read error: ' . $e->getMessage(), E_USER_WARNING); 250 } 251 } 250 if (defined('WP_DEBUG') && WP_DEBUG) { 251 trigger_error('DFEHC cache read error: ' . $e->getMessage(), E_USER_WARNING); 252 } 253 } 254 } 255 252 256 if ($val !== false) { 253 257 return $cached = (float) $val; 254 258 } 259 255 260 $fresh = dfehc_get_server_load(); 256 261 dfehc_cache_server_load($fresh); … … 258 263 } 259 264 260 function dfehc_register_minute_schedule(array $schedules): array 261 { 265 add_filter('cron_schedules', static function (array $schedules): array { 262 266 if (!isset($schedules['dfehc_minute'])) { 263 267 $schedules['dfehc_minute'] = [ … … 267 271 } 268 272 return $schedules; 269 } 270 add_filter('cron_schedules', 'dfehc_register_minute_schedule'); 271 272 if (apply_filters('dfehc_enable_load_logging', true)) { 273 }, 5); 274 275 $__dfehc_schedule = static function (): void { 276 if (!apply_filters('dfehc_enable_load_logging', true)) { 277 return; 278 } 273 279 if (!wp_next_scheduled('dfehc_log_server_load_hook')) { 274 $start = time() - (time() % 60) + 60; 275 wp_schedule_event($start, 'dfehc_minute', 'dfehc_log_server_load_hook'); 276 } 277 } 280 try { 281 $start = time() - (time() % 60) + 60; 282 wp_schedule_event($start, 'dfehc_minute', 'dfehc_log_server_load_hook'); 283 } catch (Throwable $e) { 284 if (defined('WP_DEBUG') && WP_DEBUG) { 285 trigger_error('DFEHC scheduling error: ' . $e->getMessage(), E_USER_WARNING); 286 } 287 } 288 } 289 }; 290 291 register_activation_hook(__FILE__, $__dfehc_schedule); 292 293 add_action('init', static function () use ($__dfehc_schedule): void { 294 $__dfehc_schedule(); 295 if (wp_next_scheduled('dfehc_log_server_load_hook')) { 296 remove_action('init', __FUNCTION__, 1); 297 } 298 }, 1);
Note: See TracChangeset
for help on using the changeset viewer.