nginx环境安装php扩展sphinx
时间:2014-09-26 09:06 来源:linux.it.net.cn 作者:it
一、sphinx扩展的安装
1、安装sphinxclient
复制代码代码示例:
#cd /usr/local/src
#wget http://sphinxsearch.com/files/sphinx-0.9.9.tar.gz
#tar xzvf sphinx-0.9.9.tar.gz
#cd sphinx-0.9.9/api/libsphinxclient
然后,编辑sphinxclient.c文件。
复制代码代码示例:
#vim sphinxclient.c
找到
void sock_close ( int sock );
改为
static void sock_close ( int sock );
#./configure --prefix=/usr/local/sphinxclient
#make
#make install
2、安装sphinx扩展
复制代码代码示例:
#wget http://pecl.php.net/get/sphinx-1.0.4.tgz
#tar xvzf sphinx-1.0.4.tgz
#cd sphinx-1.0.4
#/usr/local/php/bin/phpize
#./configure --with-php-config=/usr/local/php/bin/php-config --with-sphinx=/usr/local/sphinxclient
#make
#make install
修改php.ini
复制代码代码示例:
extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/"
[sphinx]
extension=sphinx.so
二,shpninx的测试
1、安装sphinx
请参考文章:http://linux.it.net.cn/e/server/2014/0926/5905.html
2、编写测试文件
#vim sphinx.php
复制代码代码示例:
<?php
/**
* 测试sphinx
* edit by www.it.net.cn
*/
$s = new SphinxClient;
setServer("localhost", 9312);
$s->setMatchMode(SPH_MATCH_ANY);
$s->setMaxQueryTime(3);
$result = $s->query("demo");
var_dump($result);
?>
#/usr/local/php/bin/php sphinx.php运行结果
array(9) {
["error"]=>
string(0) ""
["warning"]=>
string(0) ""
["status"]=>
int(0)
["fields"]=>
array(5) {
[0]=>
string(6) "cat_id"
[1]=>
string(13) "provider_name"
[2]=>
string(12) "goods_number"
[3]=>
string(18) "promote_start_date"
[4]=>
string(8) "keywords"
}
["attrs"]=>
array(8) {
["goods_sn"]=>
string(1) "3"
["goods_name"]=>
string(1) "3"
["brand_id"]=>
string(1) "1"
["goods_weight"]=>
string(1) "5"
["market_price"]=>
string(1) "5"
["shop_price"]=>
string(1) "5"
["promote_price"]=>
string(1) "5"
["gid"]=>
string(10) "1073741825"
}
["total"]=>
int(0)
["total_found"]=>
int(0)
["time"]=>
float(0)
["words"]=>
array(1) {
["demo"]=>
array(2) {
["docs"]=>
int(0)
["hits"]=>
int(0)
}
}
}
(责任编辑:IT)
一、sphinx扩展的安装
1、安装sphinxclient
复制代码代码示例:
#cd /usr/local/src
#wget http://sphinxsearch.com/files/sphinx-0.9.9.tar.gz #tar xzvf sphinx-0.9.9.tar.gz #cd sphinx-0.9.9/api/libsphinxclient
然后,编辑sphinxclient.c文件。
复制代码代码示例:
#vim sphinxclient.c
找到 void sock_close ( int sock ); 改为 static void sock_close ( int sock ); #./configure --prefix=/usr/local/sphinxclient #make #make install
2、安装sphinx扩展
复制代码代码示例:
#wget http://pecl.php.net/get/sphinx-1.0.4.tgz
#tar xvzf sphinx-1.0.4.tgz #cd sphinx-1.0.4 #/usr/local/php/bin/phpize #./configure --with-php-config=/usr/local/php/bin/php-config --with-sphinx=/usr/local/sphinxclient #make #make install
修改php.ini
复制代码代码示例:
extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/"
[sphinx] extension=sphinx.so 二,shpninx的测试
1、安装sphinx
2、编写测试文件
复制代码代码示例:
<?php
/** * 测试sphinx * edit by www.it.net.cn */ $s = new SphinxClient; setServer("localhost", 9312); $s->setMatchMode(SPH_MATCH_ANY); $s->setMaxQueryTime(3); $result = $s->query("demo"); var_dump($result); ?>
#/usr/local/php/bin/php sphinx.php运行结果
array(9) {
(责任编辑:IT)["error"]=> string(0) "" ["warning"]=> string(0) "" ["status"]=> int(0) ["fields"]=> array(5) { [0]=> string(6) "cat_id" [1]=> string(13) "provider_name" [2]=> string(12) "goods_number" [3]=> string(18) "promote_start_date" [4]=> string(8) "keywords" } ["attrs"]=> array(8) { ["goods_sn"]=> string(1) "3" ["goods_name"]=> string(1) "3" ["brand_id"]=> string(1) "1" ["goods_weight"]=> string(1) "5" ["market_price"]=> string(1) "5" ["shop_price"]=> string(1) "5" ["promote_price"]=> string(1) "5" ["gid"]=> string(10) "1073741825" } ["total"]=> int(0) ["total_found"]=> int(0) ["time"]=> float(0) ["words"]=> array(1) { ["demo"]=> array(2) { ["docs"]=> int(0) ["hits"]=> int(0) } } } |