From 8da391f54ff26b6320829ed4af8721858a2ec926 Mon Sep 17 00:00:00 2001 From: "lei.tian" Date: Thu, 30 Jun 2022 19:47:51 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dphp=E7=89=88=E6=96=87?= =?UTF-8?q?=E6=A1=A3=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- binding/php/ReadMe.md | 4 ++-- binding/php/util_test.php | 10 ++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/binding/php/ReadMe.md b/binding/php/ReadMe.md index 3ca2b8e..c8080e8 100644 --- a/binding/php/ReadMe.md +++ b/binding/php/ReadMe.md @@ -31,7 +31,7 @@ printf("{region: %s, took: %.5f ms}\n", $region, XdbSearcher::now() - $sTime); 如果你的 php 母环境支持,可以预先加载 vectorIndex 缓存,然后做成全局变量,每次创建 Searcher 的时候使用全局的 vectorIndex,可以减少一次固定的 IO 操作从而加速查询,减少 io 压力。 ```php // 1、从 dbPath 加载 VectorIndex 缓存,把下述的 vIndex 变量缓存到内存里面。 -$vIndex = XdbSearcher::loadVectorFromFile($dbPath); +$vIndex = XdbSearcher::loadVectorIndexFromFile($dbPath); if ($vIndex === null) { printf("failed to load vector index from '%s'\n", $dbPath); return; @@ -60,7 +60,7 @@ printf("{region: %s, took: %.5f ms}\n", $region, XdbSearcher::now() - $sTime); ### 缓存整个 `xdb` 数据 -如果你的 PHP 目环境支持,可以预先加载整个 `xdb` 的数据到内存,这样可以实现完全基于内存的查询,类似之前的 memory search 查询。 +如果你的 PHP 母环境支持,可以预先加载整个 `xdb` 的数据到内存,这样可以实现完全基于内存的查询,类似之前的 memory search 查询。 ```php // 1、从 dbPath 加载整个 xdb 到内存。 $cBuff = XdbSearcher::loadContentFromFile($dbPath); diff --git a/binding/php/util_test.php b/binding/php/util_test.php index 072753e..6d9cfbc 100644 --- a/binding/php/util_test.php +++ b/binding/php/util_test.php @@ -8,8 +8,10 @@ require dirname(__FILE__) . '/XdbSearcher.class.php'; +const XDB_PATH = '../../data/ip2region.xdb'; + function testLoadHeader() { - $header = XdbSearcher::loadHeaderFromFile('../../data/ip2region.xdb'); + $header = XdbSearcher::loadHeaderFromFile(XDB_PATH); if ($header == null) { printf("failed to load header from file\n"); return; @@ -20,17 +22,17 @@ function testLoadHeader() { } function testLoadVectorIndex() { - $vIndex = XdbSearcher::loadVectorIndexFromFile('../../data/ip2region.xdb'); + $vIndex = XdbSearcher::loadVectorIndexFromFile(XDB_PATH); if ($vIndex == null) { printf("failed to load vector index from file\n"); return; } - printf("vector index loaded: length=%d\n", strlen($vIndex)); + printf("vector index loaded, length=%d\n", strlen($vIndex)); } function testLoadContent() { - $cBuff = XdbSearcher::loadContentFromFile('../../data/ip2region.xdb'); + $cBuff = XdbSearcher::loadContentFromFile(XDB_PATH); if ($cBuff == null) { printf("failed to load content from file\n"); return;