【发布时间】:2014-05-20 23:06:00
【问题描述】:
我在 1 台服务器上运行了 50 个 Wordpress 安装。每个 Wordpress 网站都有一个必须每 5 分钟执行一次的脚本。我不想使用 Wordpress 的内置 cron 并想从 cron 运行脚本。最好的解决方案是什么?
*解决方案 1:为每个单独的 wordpress 安装创建一个 cron 作业 *
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
*解决方案 2:创建 1 个 cron 作业并运行 bash 脚本 *
5 * * * * /run/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
【问题讨论】:
-
我认为让一个脚本调用其余脚本更易于维护。在 crontab 中有 50 行是很难管理的。