Centos7 上 用crontab 实现php计划任务

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

systemctl status crond.service

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

yum install vixie-cron
yum install crontabs

常用指令

systemctl restart crond.service #启动服务

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

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

systemctl enable crond.service #开机自启动

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

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

相关参数

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

例子

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

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

参考:

https://segmentfault.com/a/1190000002955509
https://my.oschina.net/yangalbert/blog/496494?p={{totalPage}}

猜你喜欢

转载自blog.csdn.net/ngl272/article/details/70217094