美文网首页
使用crontab定时执行PHP

使用crontab定时执行PHP

作者: yundGo | 来源:发表于2016-11-20 20:32 被阅读0次

首先创建一个php文件,用来执行你的任务
#vi /home/a.php

<?php
  $myfile =  fopen("/home/test.txt", "a") or die("Unable to open file!");
  $txt  =  date('Y-m-d H:i:s',time())."\n";
  fwrite($myfile, $txt);
  fclose($myfile);
?>

再创建一个test文本文件
#touch /home/test.txt

php 的准备工作就完成了,下面配置crontab

找到PHP的执行路径
#whereis php

Paste_Image.png

然后配置crontab
# crontab -e

Paste_Image.png
这里是每一分钟执行一次 /home/a.php
启动crontab
#service crond start
然后看下有没有想要的效果,查看test.txt 的内容 Paste_Image.png

相关文章

网友评论

      本文标题:使用crontab定时执行PHP

      本文链接:https://www.haomeiwen.com/subject/tgyypttx.html