1、配置命令
路径:/cakephp3.8/src/Application.php
在 console 方法内 加入
//swoole聊天脚本
$commands->add('swoole_chat', new SwooleChatCommand());
当前配置命令为swoole_chat,执行类为swooleChatCommand
2、编写执行类swooleChatCommand
/**
* 命令执行
* @param Arguments $args
* @param ConsoleIo $io
* @return int|null|void
*/
public function execute(Arguments $args, ConsoleIo $io)
{
//设置执行内存
ini_set('memory_limit', '1G');
//初始化swoole
$this->_iniSwoole();
return null;
}
在execute方法内写对应的业务逻辑即可
3、服务器执行
①进入项目目录下,给bin/cake 配置执行权限
②执行命令:bing/cake swoole_chat