🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
``` <?php namespace app\common\command; use think\console\Command; use think\console\Input; use think\console\Output; use think\Db; use think\facade\Config; use think\facade\Log; use think\facade\Env; class Task extends Command { /** * 解决不能连接数据库的问题 * @param Input $input An InputInterface instance * @param Output $output An OutputInterface instance */ protected function initialize(Input $input, Output $output) { // 读取数据库配置文件 $filename = Env::get('ROOT_PATH'). 'config/database.php'; Config::load($filename, 'database'); } protected function configure() { $this->setName('task') ->setDescription('执行任务'); } protected function execute(Input $input, Output $output) { $output->writeln('task start...'); /*** 这里写计划任务列表集 START ***/ $this->finishTask($output); /*** 这里写计划任务列表集 END ***/ $output->writeln(' task end...'); } public function finishTask($output){ $time=time(); $output->writeln('任务执行完毕 花费了'.time()-$time.'秒钟,处理了'.$task_num.'任务'); } } ```