Action Scheduler is a library used by WordPress plugins (most notably WooCommerce) to handle background tasks such as sending order confirmations, processing payments, or updating stock levels.
By default, Action Scheduler processes tasks whenever someone visits your site. On high-traffic sites or sites with large amounts of data, this can cause significant delays in page load times and put unnecessary strain on the server.
Optimizing Action Scheduler Background Processes
In the Seravo environment, you can optimize the Action Scheduler with a single command: wp-action-scheduler.
This command offloads task execution from user-facing page loads and automates them to run directly via the server's scheduled tasks (Crontab).
What does the command do?
When you run the command via SSH, it automatically performs the following steps:
Installs and activates a plugin: The
action-scheduler-disable-default-runnerplugin is installed. This prevents Action Scheduler from running tasks during normal HTTP requests (site visits).Creates a Cron job: A line is added to the server's Crontab to run tasks every minute:
* * * * * /usr/local/bin/wp action-scheduler run >> /data/log/actionscheduler.logLogging: All executed tasks and potential errors are logged to
/data/log/actionscheduler.log, where they can be easily monitored in real-time.
How to Perform the Optimization
Log in via SSH.
Run the command:
wp-action-scheduler
Monitor execution in real-time:
tail -f /data/log/actionscheduler.log
Monitoring Tasks in WordPress
You can monitor the status of the task queue directly in the WordPress dashboard under Tools > Scheduled Actions.
The page provides a summary of tasks and their statuses:
Pending: Tasks waiting to be executed.
Complete: Successfully finished tasks.
Failed: Tasks that encountered an error during execution.
Canceled: Tasks that have been removed from the queue.
Once the wp-action-scheduler command has been executed, you will notice that tasks are processed consistently every minute, regardless of site traffic.
When Should You Optimize?
We especially recommend implementing this optimization if:
You are using WooCommerce and have a high volume of orders or products.
The site uses multiple plugins that generate many background tasks (e.g., WooCommerce Subscriptions or WP All Import).
You notice slowness in the WordPress dashboard, shopping cart, or checkout.
The Action Scheduler queue consistently contains thousands of pending or failed tasks.
Reverting the Optimization
If for any reason you wish to return Action Scheduler to its default settings (execution during page loads), follow these steps:
Remove the Cron job: Log in via SSH and open the crontab for editing with the command
crontab -e. Locate and delete the line starting with:
β* * * * * /usr/local/bin/wp action-scheduler runDeactivate the plugin: Deactivate the
action-scheduler-disable-default-runnerplugin either via the WordPress dashboard or the command line:wp plugin deactivate action-scheduler-disable-default-runner
Verify functionality: Check the WordPress dashboard (Tools > Scheduled Actions) to ensure tasks are once again being processed during site visits.
Important Notes
If you deactivate the action-scheduler-disable-default-runner plugin while leaving the Cron job active, tasks may attempt to run simultaneously via both HTTP requests and server-side scheduled tasks. It is recommended to always keep the plugin active whenever the optimization is in use.
