Skip to content

Instantly share code, notes, and snippets.

@DavidCramer
Created April 30, 2017 09:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DavidCramer/4fdc7646e21eeaefaed83d924cd522e1 to your computer and use it in GitHub Desktop.
Save DavidCramer/4fdc7646e21eeaefaed83d924cd522e1 to your computer and use it in GitHub Desktop.
WordPress Cron Daemon
<?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