源碼地址
安裝EASYSWOOLE
- git clone https://github.com/easy-swoole/demo.git
- git checkout 3.x-chat
- /usr/local/php7/bin/php /usr/bin/composer install
- /usr/local/php7/bin/php vender/bin/easyswoole install
安裝時遇到提示是否覆蓋 EasySwooleEvent.php蝇完、 dev.php 請選擇否 (輸入 n 回車)
啟動項目
- /usr/local/php7/bin/php easyswoole start
遇到問題
問題描述:在啟動時無法投遞一個異步任務(wù)到task_worker池中坑傅,導(dǎo)致聊天室無法加載用戶相關(guān)信息
官方文檔:https://wiki.swoole.com/wiki/page/134.html
環(huán)境配置:
swoole version 4.2.13
php version 7.2.14
easy swoole 3.1.14
namespace EasySwoole\EasySwoole\Swoole\Task;
class TaskManager
{
public static function async($task,$finishCallback = null,$taskWorkerId = -1)
{
/* 測試代碼
$task_id = ServerManager::getInstance()->getSwooleServer()->task($task,-1, function (\swoole_server $serv, $task_id, $data) {
echo "Task Callback: ";
var_dump($task_id, $data);
});
var_dump($task_id);*/
//修復(fù):針對回調(diào)函數(shù)判斷即可
$finishCallback = is_null($finishCallback) ? function (\swoole_server $serv, $task_id, $data){} : $finishCallback;
return ServerManager::getInstance()->getSwooleServer()->task($task,$taskWorkerId,$finishCallback);
}