Created
April 30, 2017 09:59
-
-
Save DavidCramer/4fdc7646e21eeaefaed83d924cd522e1 to your computer and use it in GitHub Desktop.
WordPress Cron Daemon
This file contains 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 Daemon | |
* Plugin URI: https://cramer.co.za | |
* Description: Simple plugin to daemonize the WordPress Cron. | |
* Version: 1.0.0 | |
* Author: David Cramer | |
* Author URI: https://cramer.co.za | |
* License: GPL2+ | |
*/ | |
// If this file is called directly, abort. | |
if ( ! defined( 'WPINC' ) ) { | |
die; | |
} | |
// Run only if DOING CRON and daemon_running is false. | |
if ( defined( 'DOING_CRON' ) && ! get_transient( 'daemon_running' ) ) { | |
set_transient( 'daemon_running', true ); // Flag transient as running. | |
register_shutdown_function( function () { | |
sleep( 1 ); // Sleep to give time to update and to set cycle time. | |
set_transient( 'daemon_running', false ); // Flag transient as not running. | |
$args = array( | |
'timeout' => 0.01, | |
'blocking' => false, | |
'sslverify' => false, | |
); | |
wp_remote_post( site_url( 'wp-cron.php?doing_wp_cron' ), $args ); | |
} ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment