Skip to content

Commit 1908ba5

Browse files
committed
update
1 parent ef67793 commit 1908ba5

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/ipip/db/Reader.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ public function find($ip, $language)
105105
try
106106
{
107107
$node = $this->findNode($ip);
108+
108109
if ($node > 0)
109110
{
110111
$data = $this->resolve($node);
@@ -133,24 +134,24 @@ public function findMap($ip, $language)
133134
return array_combine($this->meta['fields'], $array);
134135
}
135136

137+
private $v4offset = 0;
138+
private $v6offsetCache = [];
139+
136140
/**
137141
* @param $ip
138142
* @return int
139143
* @throws \Exception
140144
*/
141145
private function findNode($ip)
142146
{
143-
static $v4offset = 0;
144-
static $v6offsetCache = [];
145-
146147
$binary = inet_pton($ip);
147148
$bitCount = strlen($binary) * 8; // 32 | 128
148149
$key = substr($binary, 0, 2);
149150
$node = 0;
150151
$index = 0;
151152
if ($bitCount === 32)
152153
{
153-
if ($v4offset === 0)
154+
if ($this->v4offset === 0)
154155
{
155156
for ($i = 0; $i < 96 && $node < $this->nodeCount; $i++)
156157
{
@@ -168,19 +169,19 @@ private function findNode($ip)
168169
return 0;
169170
}
170171
}
171-
$v4offset = $node;
172+
$this->v4offset = $node;
172173
}
173174
else
174175
{
175-
$node = $v4offset;
176+
$node = $this->v4offset;
176177
}
177178
}
178179
else
179180
{
180-
if (isset($v6offsetCache[$key]))
181+
if (isset($this->v6offsetCache[$key]))
181182
{
182183
$index = 16;
183-
$node = $v6offsetCache[$key];
184+
$node = $this->v6offsetCache[$key];
184185
}
185186
}
186187

@@ -195,7 +196,7 @@ private function findNode($ip)
195196

196197
if ($i == 15)
197198
{
198-
$v6offsetCache[$key] = $node;
199+
$this->v6offsetCache[$key] = $node;
199200
}
200201
}
201202

0 commit comments

Comments
 (0)