From de609329875c0f59bb3436f6f5c25cd9604dfe0b Mon Sep 17 00:00:00 2001 From: "bin.wang" Date: Fri, 18 Sep 2020 17:58:13 +0800 Subject: [PATCH] add support for linux shell command --- binding/php/testSearcher_immediate.php | 62 ++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100755 binding/php/testSearcher_immediate.php 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(); + +?>