diff --git a/binding/php/testSearcher_immediate.php b/binding/php/testSearcher_immediate.php new file mode 100755 index 0000000..26cdbd9 --- /dev/null +++ b/binding/php/testSearcher_immediate.php @@ -0,0 +1,62 @@ +argv = $argv; + self::$ip2regionObj = new Ip2Region(self::$dbFile); + } + + public function run() + { + if (!empty($this->argv[1])) // cat与直接参数 + { + $len = count($this->argv); + for ($i = 1; $i <= $len - 1; $i++ ) + { + $this->search($this->argv[$i]); + } + } + else // echo 方式 + { + $ip = trim(fgets(STDIN)); + if (!empty($ip)) + { + $this->search($ip); + } + } + } + + private function getTime() + { + return (microtime(true) * 1000); + } + + private function search($ip) + { + $s_time = $this->getTime(); + $data = self::$ip2regionObj->{self::$method}($ip); + $c_time = $this->getTime() - $s_time; + printf("%s|%s in %.5f millseconds\n", $data['city_id'], $data['region'], $c_time); + } +} + +$is = new IpSearcher($argv); +$is->run(); + +?>