Linux定时任务执行PHP脚本

    xiaoxiao2022-07-02  100

    https://blog.csdn.net/why444216978/article/details/83748136

     

    1、检查是否开启crond(默认已安装)              service crond status   

              service crond start 

              service crond stop

              service crond restart

    2、编辑执行计划           crontab -e (-l查看计划列表)

              *  *  *  *  *  /usr/local/bin/php     /usr/local/nginx/html/test.php >> test.log

    3、重启crond 4、编写对应php文件 5、为php文件加权限chmod 755 test.php 6、检查mysql中数据的变化和test.log日志中的定时任务执行情况 7、查看定时任务日志:vim /var/log/cron   

    附:部分常用执行计划(分、时、日、月、周)

    每1分钟执行一次command

    * * * * * command 每小时的第3和第15分钟执行

    3,15 * * * * command 在上午8点到11点的第3和第15分钟执行

    3,15 8-11 * * * command 每隔两天的上午8点到11点的第3和第15分钟执行

    3,15 8-11 */2 * * command 每个星期一的上午8点到11点的第3和第15分钟执行

    3,15 8-11 * * 1 command 每晚的21:30重启smb

    30 21 * * * /etc/init.d/smb restart 每月1、10、22日的4 : 45重启smb

    5 4 1,10,22 * * /etc/init.d/smb restart 每周六、周日的1:10重启smb

    10 1 * * 6,0 /etc/init.d/smb restart 每天18 : 00至23 : 00之间每隔30分钟重启smb

    0,30 18-23 * * * /etc/init.d/smb restart 每星期六的晚上11:00 pm重启smb

    0 23 * * 6 /etc/init.d/smb restart 每一小时重启smb

    * */1 * * * /etc/init.d/smb restart 晚上11点到早上7点之间,每隔一小时重启smb

    * 23-7/1 * * * /etc/init.d/smb restart 每月的4号与每周一到周三的11点重启smb

    0 11 4 * mon-wed /etc/init.d/smb restart 一月一号的4点重启smb

    0 4 1 jan * /etc/init.d/smb restart 每小时执行/etc/cron.hourly目录内的脚本

    01 * * * * root run-parts /etc/cron.hourly

    带url参数的定时任务 一、curl模式:

    */1 * * * * curl http://aaa.***.com/test.php?name=xiaoming&sex=male 1 二、crontab模式

    */1 * * * * /app/bin/php /data/html/aaa.***.com/test.php -name xiaoming -sex male 原文:https://blog.csdn.net/why444216978/article/details/83748136 

    总结:关于这个crontab模式我没有调通

    解决方案:参考:https://blog.csdn.net/qq_31615139/article/details/53191519?locationNum=8&fps=1

    我最后我用workman定时了。。。

     

     

     

     

     

     

     

    最新回复(0)