Skip to content

Advanced Queue Setup In CLI mode

Ryan Hungate edited this page Aug 14, 2024 · 9 revisions

This guide details the setup of an advanced queue in CLI mode for the Mailchimp WooCommerce plugin, enhancing performance by running processes in the background, independent of web traffic.

Prerequisites

  • WP-CLI installed.
  • Knowledge of WP-CLI and WordPress installation locations on your server.
  • Ability to edit the functions.php file, preferably using a child theme or suitable plugin.

Disabling the Default Queue Runner

  1. Edit functions.php File: Include the following code:

    function asdds_disable_default_runner() {
        if ( class_exists( 'ActionScheduler' ) ) {
            remove_action( 'action_scheduler_run_queue', array( ActionScheduler::runner(), 'run' ) );
        }
    }
    add_action( 'init', 'asdds_disable_default_runner', 10 );

Running the Queue Process

Manual

Run the queue manually using WP-CLI:

wp --url=https://examplestore.com --path=/full/path/to/install/ action-scheduler run

Stop with control + c.

Automatic

  1. Set up a cron job or use a process manager like Monit or Supervisord.
  2. For cron, edit the crontab:
    crontab -e
    Add:
    * * * * * wp --url=https://examplestore.com --path=/full/path/to/install/ action-scheduler run
    Or use a process manager with:
    /usr/bin/wp --url=http://yourdomain.com --path=/full/path/to/install/ queue listen