定时任务crontab使用笔记

这里使用的是 linux里面crontab的定时任务来跑php程序

一. crontab使用到的命令

crontab -e进入crontab
service crond restart/reload 重启/重载 crontab(这里是crond)
tail -f /var/log/con 查看cron日志

二. crontab 文本中的代码

  1. 使用curl脚本执行脚本
0 3 * * * /usr/bin/curl http://xxx.com/api/method > /dev/null 2>&1 &
  1. 使用php执行程序执行脚本
0 3 * * * /usr/bin/php http://xxx.com/api/method > /dev/null 2>&1 &

使用php脚本需要注意
1.访问的文件必须要有可以让php执行程序读写的权限
2.php脚本不能使用$_SERVER等php超全局变量(不过用这种方式会比较快就是)

另外:用 whereis 软件可以很容易找到软件位置

三. crontab定时任务的时间说明

  1. */1 * * * * 每分钟执行一次
    0 3 * * * 每天早上3点执行一次

  2. 校验crontab时间的地址
    https://crontab.guru/

转载于:https://www.jianshu.com/p/960748e0fe2b

猜你喜欢

转载自blog.csdn.net/weixin_34198762/article/details/91292769