-
-
Notifications
You must be signed in to change notification settings - Fork 297
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
关于client_id服务重启后重置 #66
Comments
看了这个issue:walkor/workerman#286 |
将gatewayworker/src/Lib/Context.php 里 addressToClientId 和 clientIdToAddress 替换成如下代码。这样就加了一个时间戳前缀,避免重启后client_id冲突 /**
* 通讯地址到 client_id 的转换
*
* @param int $local_ip
* @param int $local_port
* @param int $connection_id
* @return string
*/
public static function addressToClientId($local_ip, $local_port, $connection_id)
{
return bin2hex(pack('NNnN', time(), $local_ip, $local_port, $connection_id));
}
/**
* client_id 到通讯地址的转换
*
* @param string $client_id
* @return array
* @throws Exception
*/
public static function clientIdToAddress($client_id)
{
if (strlen($client_id) !== 28) {
echo new Exception("client_id $client_id is invalid");
return false;
}
return unpack('Ntime/Nlocal_ip/nlocal_port/Nconnection_id', pack('H*', $client_id));
} |
测试了可用,非常谢谢~,我在GatewayClient\Gateway里也做了一样处理。不过这样修改源码不方便升级 |
替换了之后会出现client_id混乱,onConnect/onMessage/onClose会出现三个不同的client_id |
return bin2hex(pack('NNnN', time(), $local_ip, $local_port, $connection_id)); 改成 if (!$this->time) {
$this->time = time();
}
return bin2hex(pack('NNnN', $this->time, $local_ip, $local_port, $connection_id)); 试下。 时间戳应该是个定值,只有进程重启了才能变化。 |
非常感谢回复!可以了! |
你好,每次restart或者reload 服务,client_id都会从00000001 开始重新开始,能否有办法让client_id生成类似uuid的永久不会重复的id呢?即使服务重启也不会重复
The text was updated successfully, but these errors were encountered: