项目中遇到需要设置定时任务的工作,原先在宝塔中设置定时任务跟方便,但是却遇到如下图问题,瞬间懵逼。

决定用linux系统设置定时任务,首先需要进入项目路径下,在根据crontab命令操作,还是很简单的。
查看定时任务列表
crontab -l
添加定时任务
crontab -e
执行php 文件
* * * * * php /Data/www/wwwroot/xiangmupth/trysendsms.php
执行文件过程总发现总是报错,查看php 执行结果,可以直接在linux 中执行上步命令
php /Data/www/wwwroot/xiangmupth/trysendsms.php
发现有报错,找不到路径地址

原先以为是项目中的原因,路径地址找不到等,后面直接修改了路径地址,按照php 方法去找到,就成功了。定时任务直接就跑起来了。

比较容易的方式,大家可以尝试下。
网友评论