sphinx2安装

# 安装sphinx 2.x
cd /home/addcn
wget http://sphinxsearch.com/files/sphinx-2.1.1-beta.tar.gz
tar xvf sphinx-2.1.1-beta.tar.gz
cd sphinx-2.1.1-beta
make clean
./configure –prefix=/usr/local/sphinx –with-mysql=/usr/local/mysql
make && make install

# 配置
cd /usr/local/sphinx/etc/

# 错误
export LD_LIBRARY_PATH=”/usr/local/mysq/lib:/usr/lib:$LD_LIBRARY_PATH”

# 启动
/usr/local/sphinx/bin/searchd –config /usr/local/sphinx/etc/sphinx.conf

# 停止
/usr/local/sphinx/bin/searchd –stop

# 登入
/usr/local/mysql/bin/mysql -P9306 –protocol TCP

# 更新
/usr/local/sphinx/bin/indexer –config /usr/local/sphinx/etc/sphinx.conf –all –rotate

# 关联为实时索引
TRUNCATE RTINDEX rt;
ATTACH INDEX disk TO RTINDEX rt;

利用正则为css和js链接增加版本信息

$html = <<< HTML
<style type="text/css">import url("/css.css?a=1");</style> 
<link rel="stylesheet" type="text/css href="http://s.8591.com.tw/css/main.css"" media="all">
<link href="http://s.8591.com.tw/css/index.css" type="text/css" rel="stylesheet" media="all">
<script type='text/javascript' src='/js/jquery/jquery.js'></script>
<script src='/js/jquery/colorbox/min.js?v=1329959498' type='text/javascript'></script>
HTML;

$ver    = '1.0.3';
$p      = "/(<style.*?url\([\'\"]|<(?:link|script).*?(?:href|src)=[\"\'])([^\'\"]+)/i";
$html   = preg_replace_callback($p, create_function('$m', 'return $m[1].$m[2].(strpos($m[2], "?")?"&":"?")."_v='.$ver.'";'), $html);
echo $html;

执行结果

<style type="text/css">import url("/css.css?a=1&_v=1.0.3");</style> 
<link rel="stylesheet" type="text/css href="http://s.8591.com.tw/css/main.css?_v=1.0.3"" media="all">
<link href="http://s.8591.com.tw/css/index.css?_v=1.0.3" type="text/css" rel="stylesheet" media="all">
<script type='text/javascript' src='/js/jquery/jquery.js?_v=1.0.3'></script>
<script src='/js/jquery/colorbox/min.js?v=1329959498&_v=1.0.3' type='text/javascript'></script>