Support » Fixing WordPress » End-to-End Cron setup.

  • Hi,

    I am looking for a short guide on End-to-End Cron setup, with following steps I already did and some still waiting.

    Purpose : I have some big SQL which I cached using set_transient with timeout, however I want to run this SQL and use set_transient in cron so my end user never experience the slowless.

    Steps I thought so far,

    1. Disable the Cron job for every page load.
    A: define(‘DISABLE_WP_CRON’, true) in wp-config.php file. (DONE)

    2. Run cron at regular interval from your system.
    A: Setup cron entry with “wget -q -o – -O – -t 1 > /dev/null 2>&1. This sets output and log goes to null, quite mode and retry once only. (DONE)

    3. setup the cron schedule for every 20 mins.
    A : to add this filter
    add_filter( ‘cron_schedules’, ‘cron_add_20mins’ );
    function cron_add_20mins( $schedules ) {
    // Adds every 20mis to the existing schedules.
    $schedules[‘every20mins’] = array(
    ‘interval’ => 1200,
    ‘display’ => __( ‘Once Every20mins’ )
    return $schedules;
    (BUT I don’t know where to add this, so it execute only one time).

    4: Schedule an Once Every20mins job.
    A: to add this two filters.
    function my_activation() {
    if ( !wp_next_scheduled( ‘my_hourly_event’ ) ) {
    wp_schedule_event( time(), ‘hourly’, ‘my_hourly_event’);
    function do_this_20mins() {
    //check and cache all SQL object with set_transient.
    add_action(‘wp’, ‘my_activation’);
    add_action(‘my_hourly_event’, ‘do_this_20mins’);

    1. I guess action ‘my_hourly_event’ is not right if I want to make it every 20mins, so what it could be ?
    2. I don’t know where to add this, so it execute only one time.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Christine Rondeau


    Volunteer Forum Moderator

    Would this link help?

    WordPress: How to use WP-Cron

    Hi Christine,

    Thanks. It helps but I have two distinct question on the same ?

    1. Where can I put my add_filter( 'cron_schedules', 'cron_add_20mins' ); so It execute one time only ? I guess if I put in functions.php than it will call every time page loads.

    2. Which hook i should use to bind “add_action(‘my_hourly_event’, ‘do_this_20mins’);” , will “my_hourly_event” sufficient ?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘End-to-End Cron setup.’ is closed to new replies.