我试图在每个月的三个不同时间运行不同的脚本,每天,每个星期一和本月的第一个星期一,我已经将以下内容放在一起从这里的人,cron会每天运行一次,相应的脚本将在预设时间运行。用cron运行一个安排事件的php脚本
是否有反正我可以测试下面,而不是把它放在服务器上,等待选定日期?,我正在运行本地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设置进行大量测试。 – fkerber 2012-01-08 22:07:31
'if($ dayOfMonth <= 6)'实际上应该是'if($ dayOfMonth <= 7)'。对不起。 – yankee 2012-01-09 17:02:20