Plugin Directory

Changeset 3412883


Ignore:
Timestamp:
12/06/2025 09:58:41 AM (4 months ago)
Author:
loghin
Message:

1.2.996.2 Release

Location:
dynamic-front-end-heartbeat-control
Files:
35 added
1 deleted
3 edited

Legend:

Unmodified
Added
Removed
  • dynamic-front-end-heartbeat-control/trunk/engine/server-load.php

    r3412283 r3412883  
    489489}
    490490
    491 add_filter('cron_schedules', static function (array $schedules): array {
     491function dfehc_register_minute_schedule(array $schedules): array
     492{
    492493    if (!isset($schedules['dfehc_minute'])) {
    493494        $schedules['dfehc_minute'] = [
    494495            'interval' => 60,
    495             'display' => __('Server load (DFEHC)', 'dfehc'),
     496            'display'  => __('Server load (DFEHC)', 'dfehc'),
    496497        ];
    497498    }
    498499    return $schedules;
    499 }, 5);
    500 
    501 $__dfehc_schedule = static function (): void {
     500}
     501add_filter('cron_schedules', 'dfehc_register_minute_schedule', 5);
     502
     503function dfehc_clear_log_server_load_cron(): void
     504{
     505    if (!function_exists('wp_next_scheduled') || !function_exists('wp_unschedule_event')) {
     506        return;
     507    }
     508    while ($ts = wp_next_scheduled('dfehc_log_server_load_hook')) {
     509        wp_unschedule_event($ts, 'dfehc_log_server_load_hook');
     510    }
     511}
     512
     513function dfehc_schedule_log_server_load(): void
     514{
    502515    if (!apply_filters('dfehc_enable_load_logging', true)) {
     516        dfehc_clear_log_server_load_cron();
    503517        return;
    504518    }
     519    if (
     520        !function_exists('wp_get_schedules')
     521        || !function_exists('wp_next_scheduled')
     522        || !function_exists('wp_schedule_event')
     523    ) {
     524        return;
     525    }
     526    $schedules = wp_get_schedules();
     527    if (!isset($schedules['dfehc_minute'])) {
     528        dfehc_clear_log_server_load_cron();
     529        return;
     530    }
    505531    if (!wp_next_scheduled('dfehc_log_server_load_hook')) {
     532        $interval = (int) $schedules['dfehc_minute']['interval'];
     533        $now      = time();
     534        $start    = $now - ($now % $interval) + $interval;
    506535        try {
    507             $now = time();
    508             $start = $now - ($now % 60) + 60;
    509536            wp_schedule_event($start, 'dfehc_minute', 'dfehc_log_server_load_hook');
    510537        } catch (Throwable $e) {
     
    514541        }
    515542    }
    516 };
    517 
    518 register_activation_hook(__FILE__, $__dfehc_schedule);
    519 
    520 add_action('init', static function () use ($__dfehc_schedule): void {
    521     $__dfehc_schedule();
    522 }, 1);
     543}
     544
     545if (function_exists('register_activation_hook')) {
     546    register_activation_hook(__FILE__, 'dfehc_schedule_log_server_load');
     547}
     548
     549function dfehc_deactivate_log_server_load(): void
     550{
     551    dfehc_clear_log_server_load_cron();
     552}
     553
     554if (function_exists('register_deactivation_hook')) {
     555    register_deactivation_hook(__FILE__, 'dfehc_deactivate_log_server_load');
     556}
     557
     558add_action('init', 'dfehc_schedule_log_server_load', 1);
    523559
    524560function dfehc_load_acquire_lock(): bool
  • dynamic-front-end-heartbeat-control/trunk/heartbeat-async.php

    r3412705 r3412883  
    3939        return set_transient($key, $value, $ttl);
    4040    }
    41 }
    42 
    43 function dfehc_client_ip(): string
    44 {
    45     $ip = isset($_SERVER['REMOTE_ADDR']) ? (string) $_SERVER['REMOTE_ADDR'] : '0.0.0.0';
    46     $trusted = (array) apply_filters('dfehc_trusted_proxies', []);
    47     if ($trusted && in_array($ip, $trusted, true)) {
    48         $headers = (array) apply_filters('dfehc_proxy_ip_headers', ['HTTP_X_FORWARDED_FOR', 'HTTP_CF_CONNECTING_IP', 'HTTP_X_REAL_IP']);
    49         foreach ($headers as $h) {
    50             if (!empty($_SERVER[$h])) {
    51                 $raw = (string) $_SERVER[$h];
    52                 $parts = array_map('trim', explode(',', $raw));
    53                 $cand = end($parts);
    54                 if ($cand) {
    55                     return $cand;
    56                 }
    57             }
    58         }
    59     }
    60     return $ip;
    6141}
    6242
  • dynamic-front-end-heartbeat-control/trunk/readme.txt

    r3412720 r3412883  
    33Tested up to:      6.9
    44Requires PHP:      7.2
    5 Stable tag:        1.2.996.1
     5Stable tag:        1.2.996.2
    66License:           GPLv2 or later
    77License URI:       https://www.gnu.org/licenses/gpl-2.0.html
     
    4949== Changelog ==
    5050
     51= 1.2.996.2 =
     52
     53* Improved cron scheduling.
    5154
    5255= 1.2.996.1 =
Note: See TracChangeset for help on using the changeset viewer.