Last active
February 25, 2026 08:56
-
-
Save bgrgicak/614b34a38d51fe30c6c3348a841798b1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Plugin Name: Cron Sleep Test | |
| * Description: A 15-second cron job that runs on every page load. | |
| * Version: 3.1.0 | |
| */ | |
| if ( ! defined( 'WP_CRON_LOCK_TIMEOUT' ) ) { | |
| define( 'WP_CRON_LOCK_TIMEOUT', 1 ); | |
| } | |
| add_filter( 'cron_schedules', function ( $schedules ) { | |
| $schedules['every_second'] = array( | |
| 'interval' => 1, | |
| 'display' => 'Every Second', | |
| ); | |
| return $schedules; | |
| } ); | |
| add_action( 'init', function () { | |
| if ( ! wp_next_scheduled( 'cron_sleep_test_event' ) ) { | |
| wp_schedule_event( time(), 'every_second', 'cron_sleep_test_event' ); | |
| } | |
| } ); | |
| add_action( 'cron_sleep_test_event', function () { | |
| $start = microtime( true ); | |
| error_log( '[Cron Sleep Test] Started at ' . gmdate( 'Y-m-d H:i:s' ) ); | |
| sleep( 15 ); | |
| $elapsed = round( microtime( true ) - $start, 2 ); | |
| error_log( '[Cron Sleep Test] Finished at ' . gmdate( 'Y-m-d H:i:s' ) . " (ran for {$elapsed}s)" ); | |
| } ); | |
| register_deactivation_hook( __FILE__, function () { | |
| wp_clear_scheduled_hook( 'cron_sleep_test_event' ); | |
| } ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment