使用 cron 运行一个 php 脚本来安排事件 [英] run a php script with cron that schedules events

查看:51
本文介绍了使用 cron 运行一个 php 脚本来安排事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在每个月的三个不同时间运行不同的脚本,每天,每个星期一和本月的第一个星期一,我在人们的帮助下整理了以下内容,cron 将运行这个每天一次,相应的脚本将在预设的时间运行.

I am trying to run a different script on the three different time of the month, every day, every Monday and the first Monday of the month, I have put together the following with help from people on here, cron will run this once a day and the corresponding scripts will get run at the pre set times.

除了将其放在服务器上并等待选定的日期之外,还有什么可以测试以下内容吗?,我正在运行本地 apache 服务器,如果我将日期更改为该月的第一天并运行它,这样可以吗?.

Is there anyway I can test the following other than putting it on the server and waiting for the selected dates ?, I am running a local apache server, if I change the date on that to the first day of the month and run it, would this be ok ?.

这一切都正确吗?:

<?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';
}
?>

推荐答案

我只是通过手动设置这些变量来测试它:

I'd test it by just manually setting those variables:

date_default_timezone_set('Europe/London');
//$weekday = date('D');
//$dayOfMonth = date('d');
$weekday = 4;      // <-----------
$dayOfMonth = 14;  // <-----------
// runs the everyday php file
echo '$RUN_everyday';

将其更改为您想要测试并触发它的任何值 - 看看会发生什么!

Change that to whatever values you want to test and trigger it - see what happens!

这篇关于使用 cron 运行一个 php 脚本来安排事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆