利用crontab执行php脚本

1.执行的php脚本内容

<?php $myfile = fopen("/home/wwwlogs/crontab.txt", "a+");//这里写相对路径不行 $txt = "crontab job\n"; fwrite($myfile, $txt); fclose($myfile); ?>

2.添加定时任务
每两分钟执行一次php脚本
crontab -e 输入以下内容

*/2 * * * * /usr/bin/php /home/wwwroot/test.com/zq.php

在这里插入图片描述
执行结果:
在这里插入图片描述
示例二:通过crontab执行php脚本往数据库中插入数据

在这里插入图片描述
在这里插入图片描述
添加定时任务
crontab -e
*/1 * * * * /user/bin/php /home/wwwroot/test.com/test.php
在这里插入图片描述

通过curl 或者wget执行php脚本本的某一个方法
*/1 * * * * curl http://small.yigo.fun/test
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/u014265398/article/details/86365740
今日推荐