echo "send stop"; } else { if ($msg['type'] == 'join') { echo 'join'; $client = new RouterClient('127.0.0.1', 9010); $sid = $_SERVER['SESSIONID']; $msg['id'] = $sid; $msg['x'] = mt_rand(0, 600 - 48); $msg['y'] = mt_rand(0, 520 - 64); //write to db $redis = new Redis(); $key = 'role:' . $sid; $redis->connect('localhost', 6379); $redis->hMset($key, array('id' => $msg['id'], 'x' => $msg['x'], 'y' => $msg['y'], 'name' => $msg['name'])); //join ok $client->sendMsg($sid, json_encode(array('type' => 'joinok', 'id' => $sid, 'name' => $msg['name']))); //sync $keys = $redis->keys('role:*'); $list = array(); foreach ($keys as $k) { $data = $redis->hgetAll($k); if ($k == $key) { continue; } $data['type'] = 'join'; $client->sendMsg($sid, json_encode($data)); echo "sync-->" . $data['id'] . "\n"; } //send all $client->sendAllMsg(json_encode($msg)); } else {