Configuring CRONS

Municipio will disable WPCron by default, as it is not suitable for larger network sites. Instead, we provide documentation on how to configure crontab effectively.

Separation of relevant cronjobs:

# Wp Cron actions (PROD)
*/10 * * * * cd /var/www/prod/ && /usr/local/bin/wp site list --field=url --public=1 --allow-root | xargs -I -P 4 \% /usr/local/bin/wp cron event run --exclude=wp_stream_auto_purge,import_events_daily,import_volunteer_assignments_daily,import_avalable_job_list_JobLis>
*/15 * * * * cd /var/www/prod/ && /usr/local/bin/wp site list --field=url --public=1 --allow-root | xargs -I -P 4 \% /usr/local/bin/wp cron event run import_events_daily --due-now --url=\% --allow-root > /var/log/cron-event-prod-event.log 2>&1
5-59/15 * * * * cd /var/www/prod/ && /usr/local/bin/wp site list --field=url --public=1 --allow-root | xargs -P 4 -I \% /usr/local/bin/wp cron event run import_volunteer_assignments_daily --due-now --url=\% --allow-root > /var/log/cron-event-prod-volunteer.log 2>&
10-59/15 * * * * cd /var/www/prod/ && /usr/local/bin/wp site list --field=url --public=1 --allow-root | xargs -P 4 -I \% /usr/local/bin/wp cron event run import_avalable_job_list_JobListings_Cron_ReachmeeImport --due-now --url=\% --allow-root > /var/log/cron-event-pr>
30 3 * * * cd /var/www/prod/ && /usr/local/bin/wp site list --field=url --public=1 --allow-root | xargs -I \% /usr/local/bin/wp cron event run broken-links-detector-external --due-now --url=\% --allow-root > /var/log/cron-event-prod-link.log 2>&1
30 4 * * * cd /var/www/prod/ && /usr/local/bin/wp site list --field=url --public=1 --allow-root | xargs -I \% /usr/local/bin/wp cron event run wp_stream_auto_purge --due-now --url=\% --allow-root > /var/log/cron-event-prod-stream.log 2>&1

Here’s a breakdown of what your cron job does:

Every 15 minutes, it changes the directory to /var/www/prod/.
It runs /usr/local/bin/wp site list –field=url –public=1 –allow-root to get a list of URLs.
It pipes this list of URLs to xargs, which replaces the placeholder % with each URL and runs the command /usr/local/bin/wp cron event run import_events_daily –due-now –url=% –allow-root.
Since xargs executes commands sequentially by default, each wp cron event run command will wait for the previous one to complete before starting.

If you want to run the commands in parallel, you can use the -P option of xargs to specify the number of commands to run in parallel. For example, to run up to 4 commands in parallel, you would modify your cron job like this:

Did this article help you?