public static function onWorkerStart($businessWorker)
? ? {
? ? ? ? global $db;
?
? ? ? ? require_once __DIR__ . '/demo.php';
? ? ? ? $db = new demo();
? ? }
?
? ? /**
? ? ?* 當(dāng)客戶端發(fā)來消息時(shí)觸發(fā)
? ? ?* @param int $client_id 連接id
? ? ?* @param mixed $message 具體消息
? ? ?*/
? ? public static function onMessage($client_id, $message)
? ? {
? ? ? ?global $db;
?
? ? ? ? $data=json_decode($message,true);
if ($data=='edit'){
$db->info=$data;
$content='設(shè)置成功';
}else{
$content=!empty($db->info)?$db->info:'沒有值';
}
? ? ? ? Gateway::sendToAll($content);
? ? }
$db->info的值是共享的,可以設(shè)為每個(gè)客戶端讀取自己設(shè)置的值嗎?
比如1客戶設(shè)置了內(nèi)容:123456 ,另外幾個(gè)客戶端取到這個(gè)對像的值也是123456了
$db->info弄成數(shù)組,$db->info =xxx。
但是這樣不太好,隨著客戶端越來越多,這個(gè)數(shù)組越來越大,然后內(nèi)存就不斷變大。會出問題