THINKPHP5 內(nèi)使用 Gateway::sendToClient($client_id,$str);就會(huì)報(bào)這個(gè)錯(cuò),最奇怪的是有時(shí)候很小概率能成功不報(bào)錯(cuò).煩請(qǐng)解惑
我重啟電腦后,又正常了。當(dāng)我重啟服務(wù)后,又出現(xiàn)這個(gè)問(wèn)題!
namespace app\worker\controller;
use \GatewayWorker\Lib\Gateway;
use think\Db;
use think\Controller;
class Index extends Controller{
public function initUser(){
$uid = input('post.uid');
$client_id = input('post.client_id');
// $uid = $uid ? $uid : 1;
// $client_id = $client_id ? $client_id : "7f00000108fc00000006";
Gateway::$registerAddress = '0.0.0.0:1236';
Gateway::bindUid($client_id, $uid); // 執(zhí)行到這里就報(bào)錯(cuò)了
Gateway::joinGroup($client_id, $uid);
dump($uid);
dump($client_id);
}
public function doSomeThing(){
$arr = Db::query("select * from sw_user");
$json = json_encode($arr,true);
$uid = input('post.uid');
dump($json);
if(!is_array($json)){
// Gateway::sendToAll($json);
// Gateway::sendToClient($client_id,$json);
Gateway::sendToUid($uid,$json);
Gateway::sendToGroup($uid,$json);
}
}
}
Gateway::$registerAddress = '0.0.0.0:1236';
這個(gè)明顯錯(cuò)了,應(yīng)該是ip:1236,ip不能是0.0.0.0
我遇到這個(gè)問(wèn)題,是windows系統(tǒng),register正常啟動(dòng)后ctrl+c關(guān)閉了,再啟動(dòng)register時(shí),thinkPHP框架內(nèi)的gatewayclient就無(wú)法鏈接register了,這時(shí)候重啟一下Apache,就又可以鏈接register的端口了。感覺(jué)還是windows系統(tǒng)或者是Apache(我用的PHPstudy)的問(wèn)題,希望遇到這個(gè)問(wèn)題的人,試一下方法是不是有效,也希望walkor查找下問(wèn)題原因。