## 1:创建两个监听事件 ~~~ php think make:listener SwooleTask ~~~ ~~~ php think make:listener SwooleTaskFinish ~~~ ## 2 :在`event.php`加入如下代码: ~~~ // 事件定义文件 return [ 'bind' => [ ], 'listen' => [ 'AppInit' => [], 'HttpRun' => [], 'HttpEnd' => [], 'LogLevel' => [], 'LogWrite' => [], 'swoole.task'=>['\app\listener\SwooleTask'], 'swoole.finish'=>['\app\listener\SwooleTaskFinish'], ], 'subscribe' => [ ], ]; ~~~ ### 3: app/config/xhy.php 增加多任务映射关系 ~~~ /** * 异步task 任务映射 * */ 'task' => [ 'test' => [ 'task' => app\listener\test\Task::class, 'finish' => app\listener\test\Finish::class, ], // 请求北京api 'CheckTask'=>[ 'task' => app\listener\CheckTask\Task::class, // 'finish' => app\listener\CheckTask\Finish::class, ], //错题记录 'Mistakes' =>[ 'task'=> app\listener\Mistakes\Task::class, ] ], ~~~ ~~~