在PHP中创建并执行cron作业 [英] Create and execute the cron job in PHP
本文介绍了在PHP中创建并执行cron作业的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有类似的线程,我已经经历了。他们不会清除我的疑虑。
There are similar thread, I already went through. They don't clear my doubts please!
refresh.php
refresh.php
<?php
echo "This code will run every minute";
if(count!=1)
count+=1;
else
$count = 1;
echo $count;
?>
cron.php
<?php
exec('echo -e "`crontab -l`\n30 1 * * * /opt/lamt/htdocs/refresh.php" | crontab -'); //to run at 1:30 am
?>
- 如何在晚上10:30运行?
- 如何执行
cron.php
??
- How to run this at 10:30 pm ?
- How to execute
cron.php
??
推荐答案
打开shell并输入:
Open shell and type this:
command="php /opt/lamt/htdocs/refresh.php"
job="30 22 * * * $command"
cat <(fgrep -i -v "$command" <(crontab -l)) <(echo "$job") | crontab -
上面的代码创建了一个cronjob来执行 / opt / lamt / htdocs /refresh.php
每天在 22.30
。
The above creates a cronjob that executes /opt/lamt/htdocs/refresh.php
every day at 22.30
.
command="php /opt/lamt/htdocs/refresh.php"
job="30 10 * * * $command"
cat <(fgrep -i -v "$command" <(crontab -l)) <(echo "$job") | crontab -
上面的代码创建了一个cronjob来执行 / opt / lamt / htdocs /refresh.php
每天在 10.30
。
The above creates a cronjob that executes /opt/lamt/htdocs/refresh.php
every day at 10.30
.
这是正确的 crontab
语法:
# * * * * * command to execute
# ┬ ┬ ┬ ┬ ┬
# │ │ │ │ │
# │ │ │ │ │
# │ │ │ │ └───── day of week (0 - 7) (0 to 6 are Sunday to Saturday, or use names; 7 is Sunday, the same as 0)
# │ │ │ └────────── month (1 - 12)
# │ │ └─────────────── day of month (1 - 31)
# │ └──────────────────── hour (0 - 23)
# └───────────────────────── min (0 - 59)
这篇关于在PHP中创建并执行cron作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文