ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
`config`下新建 <details> <summary>task.php</summary> ~~~ <?php //swoole.task配置文件 return [ //任务关键字提取 'key' => 'cmd', //任务别名 'alias' => [ //名称 'order' => [ //调用类 'class' => \app\job\Task::class, //执行方法 'methods' => [ 'func1', 'func2', ], //触发task.finish 'finish' => true ] ], ]; ~~~ </details> `app/job`下新建 <details> <summary>Task.php</summary> ~~~ <?php namespace app\job; class Task { public function func1($data) { dump('func1'); dump($data); } public function func2($data) { dump('func2'); dump($data); } } ~~~ </details> 在控制器中调用task投递任务 ~~~ $server->task(['time' => time()]); $server->task(['cmd' => 'order', 'time' => time()]); ~~~ 测试结果: ![](https://img.kancloud.cn/57/34/5734326cd330efb8638dcb047a719392_396x285.png) <blockquote class="danger">注意:在服务启动时(SwooleBoot.php)会对task.php的alias进行检查!若检查失败则停止启动!</blockquote> ![](https://img.kancloud.cn/b4/15/b4158c1ff2affad23540e28e95368702_638x177.png)