Parallel queue processing.

If you are sending 100,000s of emails a single instance of the queue processing events 1 by 1 may not suffice as it would take hours for all your emails to be sent.

If you're in this situation follow these steps to set up  parallel queue processing. This setup totally bypasses the WP-Cron infrastructure and offers a direct execution path to the Groundhogg event queue.

First,

You will need to create a new file call gh-cron.php in your main directory (the same place as your wp-config.php file).

Next,

You will need to add the following content to the gh-cron.php file you just created.

<?php
/**
 * This file can be used to process the event queue directly without the overhead of other WordPress tasks.
 * Call this file directly from a sever Cron
 *
 * @package WordPress
 */

ignore_user_abort( true );

/* Don't make the request block till we finish, if possible. */
if ( function_exists( 'fastcgi_finish_request' ) && version_compare( phpversion(), '7.0.16', '>=' ) ) {
    if ( ! headers_sent() ) {
        header( 'Expires: Wed, 11 Jan 1984 05:00:00 GMT' );
        header( 'Cache-Control: no-cache, must-revalidate, max-age=0' );
    }

    fastcgi_finish_request();
}

if ( ! empty( $_POST ) || defined( 'DOING_AJAX' ) || defined( 'DOING_CRON' ) ) {
    die();
}

/**
 * Optional password lock to avoid expensive DDOS attacks
 */
# define( 'GH_CRON_PASS', 'your_password' );
#
# if ( $_GET[ 'pass' ] !== GH_CRON_PASS ){
#    die();
# }

/**
 * Tell WordPress we are doing the CRON task.
 *
 * Keep for compatibility
 * 
 * @var bool
 */
define( 'DOING_CRON', true );

if ( ! defined( 'ABSPATH' ) ) {
    /** Set up WordPress environment */
    require_once( dirname( __FILE__ ) . '/wp-load.php' );
}

do_action( 'groundhogg_process_queue' );

die();

Last,

You will need to set up multiple external cron jobs to make a request to the file you just created which will be located at https://www.yoursite.com/gh-cron.php.

Follow this documentation on how to create an external cron job but instead of using the wp-cron.php use gh-cron.php instead.

The thing about this file is unlike the WP-Cron system the Groundhogg event queue can run in parallel with other instances. This means you can have multiple instances of the event queue processing events within 60 seconds of each other without colliding.

2 cron jobs will process the event queue twice as fast, 3 will process the queue 3 times as fast, etc...

Double the speed of the processing by adding an additional cron job.

Drawbacks

This will put a larger load on your server. This means you will need to have a hosting plan sufficient enough to handle the load.

If you set up an external cron in the traditional way, you can't easily turn it on or off, meaning you will have multiple cron jobs pinging your site even if there are no events to process, putting more unnecessary load on your server.

Only use this process if absolutely necessary.

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us