这里使用的是 linux
里面crontab
的定时任务来跑php
程序
一. crontab
使用到的命令
crontab -e
进入crontab
service crond restart/reload
重启/重载 crontab
(这里是crond
)
tail -f /var/log/cron
查看cron
日志
二. crontab
文本中的代码
- 使用
curl
脚本执行脚本
0 3 * * * /usr/bin/curl http://xxx.com/api/method > /dev/null 2>&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 * * * *
每分钟执行一次
0 3 * * *
每天早上3点执行一次 -
校验crontab时间的地址
https://crontab.guru/
网友评论