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