【发布时间】:2012-01-08 22:02:27
【问题描述】:
我正在尝试在每个月的三个不同时间运行不同的脚本,每天、每个星期一和每月的第一个星期一,我在这里的人的帮助下整理了以下内容,cron 将运行这个每天一次,相应的脚本将在预设的时间运行。
除了将其放在服务器上并等待选定的日期之外,我是否可以测试以下内容?,我正在运行本地 apache 服务器,如果我将日期更改为该月的第一天并运行它,这样可以吗?。
这一切都正确吗? :
<?php
$RUN_everyday = `/path/to/php/everyday.php`;
$RUN_everymonday = `/path/to/php/everymonday.php`;
$RUN_firstmondayofmonth = `/path/to/php/firstmondayofmonth.php`;
date_default_timezone_set('Europe/London');
$weekday = date('D');
$dayOfMonth = date('d');
// runs the everyday php file
echo '$RUN_everyday';
if ($weekday == 'Mon')
{
//runs the every monday php file every monday of the week
echo '$RUN_everymonday';
if ($dayOfMonth <=6)
//runs the first monday of the month php file on the first monday of each month
echo '$RUN_mondayofmonth';
}
?>
【问题讨论】:
-
我的想法是否正确,您使用 cron 来触发此脚本的执行?而这个脚本本身应该触发其他三个脚本?为什么不直接用cron来触发这三个脚本呢?因为它非常直观,所以我还要说不需要对 cron 设置进行大量测试。
-
if ($dayOfMonth <=6)实际上应该是if ($dayOfMonth <=7)。很抱歉。