Skip to content

Commit

Permalink
修复swoole获取本机网卡ip的bug
Browse files Browse the repository at this point in the history
修复swoole获取本机网卡ip的bug
  • Loading branch information
qieangel2013 committed Nov 3, 2016
1 parent f0521c9 commit 6da6181
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion application/library/distributed.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public function __construct() {
$config_obj=Yaf_Registry::get("config");
$distributed_config=$config_obj->distributed->toArray();
$localinfo=swoole_get_local_ip();
if (!$this->client->connect($localinfo['eth0'],$distributed_config['port'], -1))
if (!$this->client->connect(current($localinfo),$distributed_config['port'], -1))
{
exit("connect failed. Error: {$client->errCode}\n");
}
Expand Down
2 changes: 1 addition & 1 deletion distributed/server/DistributedClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function onConnect($serv)
'data' => array(
'code' => 10001,
'status' => 1,
'fd' => $localinfo['eth0']
'fd' => current($localinfo)
)
)));
}
Expand Down
6 changes: 3 additions & 3 deletions distributed/server/DistributedServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,12 @@ public function __construct()
public function onStart($serv)
{
$localinfo = swoole_get_local_ip();
$this->localip = $localinfo['eth0'];
$this->localip = current($localinfo);
$serverlist = DistributedClient::getInstance()->getserlist();
$result_fd = json_decode($serverlist, true);
if (!empty($result_fd)) {
foreach ($result_fd as $id => $fd) {
if ($fd != $localinfo['eth0']) {
if ($fd != $this->localip) {
$client = DistributedClient::getInstance()->addServerClient($fd);
$this->table->set(ip2long($fd), array(
'serverfd' => ip2long($fd)
Expand All @@ -126,7 +126,7 @@ public function onConnect($serv, $fd)
{
$this->connectioninfo = $serv->connection_info($fd);
$localinfo = swoole_get_local_ip();
$this->localip = $localinfo['eth0'];
$this->localip = current($localinfo);
if ($this->localip != $this->connectioninfo['remote_ip']) {
$this->client_pool[ip2long($this->connectioninfo['remote_ip'])] = array(
'fd' => $fd,
Expand Down

0 comments on commit 6da6181

Please sign in to comment.