美文网首页
定时任务crontab使用笔记

定时任务crontab使用笔记

作者: 蟠龙有悔 | 来源:发表于2019-06-02 17:38 被阅读0次

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

    一. crontab使用到的命令

    crontab -e进入crontab
    service crond restart/reload 重启/重载 crontab(这里是crond)
    tail -f /var/log/cron 查看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 /var/www/html/project/public/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/

    相关文章

      网友评论

          本文标题:定时任务crontab使用笔记

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