Linux利用CronTab定时执行ThinkPHP命令行模式
ThinkPHP试用命令行模式
<?php
namespace app\appname\command;
use think\console\Command;
use think\console\Input;
use think\console\Output;
class Test extends Command {
protected function configure() {
//可选 设置名称与描述
$this -> setName('this is name') -> setDescription('this is description');
}
//具体的执行方法
protected function execute(Input $input, Output $output) {
//这里操作具体的实现方法
echo "Hello World!";
}
}
Centos7安装和使用Crontab
yum -y install vixie-cron
yum -y install crontab
//cron 是 linux 的内置服务,但它不自动起来
//可以用以下的方法启动、关闭这个服务:
service crond start //启动服务
service crond stop //关闭服务
service crond restart //重启服务
service crond reload //重新载入配置
service crond status //查看crontab服务状态
//在CentOS系统中加入开机自动启动:
chkconfig --level 345 crond on
编写定时启动设置
crond -e
0 4 * * * /usr/local/php71/bin/php /data/wwwroot/www.xxx.com/wuye/think test
//每天4点0分执行这个test命令