Centos7 上 用crontab 实现php计划任务

Centos7 上 用crontab 实现php计划任务

原创 2017年04月17日 22:44:26
  • 1790

首先用命令检查服务是否在运行

systemctl status crond.service
  • 1

如果服务器上没有装有crontab ,则可以执行

yum install vixie-cron
yum install crontabs
  • 1
  • 2

常用指令

systemctl restart crond.service #启动服务

systemctl reload crond.service #重新载入配置

systemctl status crond.service #查看crontab服务状态

systemctl enable crond.service #开机自启动
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

启动服务之后可以输入指令

crontab -e #进入定时任务编辑
  • 1

相关参数

基本格式 :  
* *   *  *  *  command  
分  时  日  月  周  命令  
第1列表示分钟1~59 每分钟用*或者 */1表示  
第2列表示小时1~23(0表示0点)  
第3列表示日期1~31  
第4列表示月份1~12  
第5列标识号星期0~6(0表示星期天)  
第6列要运行的命令
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

例子

*/2 * * * * curl -o /home/index.html www.baidu.com #每隔两分钟使用curl 访问www.baidu.com 并将结果写入/home/index.html 文件
  • 1

将后面的指令换成服务器php需要定时循环的任务接口即可

参考:

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章