Most efficient way to trigger wp-cron through system cron.

I have recently decided it would be best if i disable the built in wordpress cron function and move to the system cron which will activate the wordpress cron every 15 minutes.

I am wondering which way is best and what the differences are performance wise etc?

The two ways I have seen this done are:

curl http://example.com/wp-cron.php?doing_wp_cron  /dev/null 21

and

cd /var/www/example.com/htdocs; php /var/www/example.com/htdocs/wp-cron.php?doing_wp_cron  /dev/null 21

Which way is better, and what are the benefits of a certain way?
Any advice would be great and appreciated!

Topic wp-cron cron linux Wordpress

Category Web


Directly execute cron via CLI, either with the php command or WP CLI, e.g.

wp cron event run --due-now --url="..."

If you ping the cron URL with curl, then wp-cron will still have all the restrictions in place such as memory limits execution time limits. CLI PHP can use unlimited memory/time (hardware permitting).

Note that you will need to run the command for each subsite in the network


The official wordpress documentation https://developer.wordpress.org/plugins/cron/hooking-into-the-system-task-scheduler/ suggests doing it via a web request rather as per your first example rather than php CLI as per your second example. Their example uses wget, but your curl request would work just as well. I believe they are using the web request replicates the standard http requests that would otherwise trigger wp-cron.php.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.