Run Action Scheduler from our Control Panel

Action Scheduler is used by WordPress applications (most notably WooCommerce) to schedule actionable hooks in the future. It is a very handy tool that extends the functionality of the already built-in action function. But for some sites it can pile up, bloat your database and even slow down your site. This isn’t necessarily because of Action Scheduler itself, but because the current setup of the site. For more information on Action Scheduler check out their official site.

While Action Scheduler is built to properly clean up after itself, it can benefit from running at a bigger interval. The easiest way to do this is by disabling it from either the functions.php file or by making a plugin. Then set it up to run from server cron in our Control Panel. I’ll show you here how to make the plugin;

Note that this assumes you know how to use either SSH with terminal commands or SFTP

What you need to do is to make a PHP file with some code in it. You can call it something like disable_action_scheduler.php and add the code below into it:

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

This then needs to be made or placed in your ~/plugins/wp-content/mu-plugins/ folder either with SSH directly, or uploaded with SFTP. If the mu-plugins folder doesn’t exist already you can simply make it on the server.

Great! You have now disabled action scheduler but we still want it to run of course. Navigate to your site in our Control Panel and then to the Cron section. Here you can add this cron job:

*/2 * * * *

wp action-scheduler run --path=/path/to/your/webroot/ --quiet

You can find the webroot URI under the Server Login Info in our Control Panel. For more detailed info about what the webroot is, check out this article.

All done! You have now set up Action Scheduler to run on a set interval of two minutes from server cron instead of WP cron.

And as always, should you have any questions please don’t hesitate to contact our support at servebolt.com!

Give us your feedback on this article