I have 50 WordPress installations running on 1 server. Every WordPress website has a script which must execute every 5 minutes. I don’t want to use the build-in cron of WordPress and want to run the scripts from cron. What is the best solution?
*Solution 1: create a cron job for every individual wordpress installation *
5 * * * * /usr/bin/php /wordpress-site-1/cron.php
5 * * * * /usr/bin/php /wordpress-site-2/cron.php
5 * * * * /usr/bin/php /wordpress-site-3/cron.php
... + 47 other scripts
*Solution 2: create 1 cron job and run a bash script *
5 * * * * /run/the-script
The script:
#!/bin/bash
# include the 50 sites in array
array=( wordpress-site-1 wordpress-site-2 wordpress-site-3 ...)
for i in "${array[@]}"
do
{execute php file)
done
By far, having 50 singular crons is much more efficient than have it run in one script. The only downside is that you’ll have to insert 50 lines in your crontab. But hey, if that’s everything…
Reasons for having 50 crons instead of one:
As for the last point (dividing payload), I’d suggest to execute the first 10 scripts at zero, 5-past, 10-past etc, and the next 10 scripts a minute later. This way they don’t run all at once, causing a high peak-load every 5 minutes:
This is a pattern that you could use:
try this solution:
Then:
NOTE: You can use
for loop
to make it easier.if you want every script run per 5 min, you can do this: