- wget http://tokyocabinet.sourceforge.net/tokyocabinet-1.4.28.tar.gz
- tar zxvf tokyocabinet-1.4.28.tar.gz
- cd tokyocabinet-1.4.28/
- ./configure --prefix=/usr/local/tc
- #./configure --prefix=/usr/local/tc --enable-off64
- wget http://tokyocabinet.sourceforge.net/tyrantpkg/tokyotyrant-1.1.29.tar.gz
- tar zxvf tokyotyrant-1.1.29.tar.gz
- cd tokyotyrant-1.1.29/
- ./configure --prefix=/usr/local/tt --with-tc=/usr/local/tc
- make
- make install
- #make uninstall 卸载
- [root@localhost /]# whereis ttserver -> /usr/local/bin/ttserver
- [root@localhost /]# cd /usr/local/sbin
- [root@localhost bin]# ttserver -host 127.0.0.1 -port 1978 -thnum 8 -dmn -pid /var/db/ttserver/ttserver.pid -log /var/db/ttserver/ttserver.log -le -ulog /var/db/ttserver/ -ulim 128m
- [root@localhost bin]# ps uax |grep ttserver //查找运行的进程
- [root@localhost ttserver]# ttserver -host 127.0.0.1 -port 1978 -thnum 8 -dmn -pid /var/db/ttserver/ttserver.pid -log /var/db/ttserver/ttserver.log -le -ulog /var/db/ttserver/ -ulim 128m -sid 1 -rts /var/db/ttserver/ttserver.rts /var/db/ttserver/database.tch#bnum=1000000
- tar zxvf tokyo_tyrant-0.5.0.tgz
- cd tokyo_tyrant-0.5.0
- /usr/local/php/bin/phpize
- ./configure --with-tokyo-tyrant=/usr/local/tt/ --with-tokyo-cabinet-dir=/usr/local/tc/
- #TT指定目录安装时,给出tt和tc的目录位置,否则会提示,reinstall tokyo-tyrant
- make && make install
- <?php
- define('TT_PATH', substr(dirname(__FILE__), 0, -7));
- require_once(TT_PATH.'/bbs/TokyoTyrant.php');
- $ttObject = new Net_TokyoTyrant();
- $memObject = new Memcache();
- //连接TT
- $memObject->connect('192.168.1.111',1979);
- //写入点击数 以 fid_$fid 为 Key 保存对应的域名值
- function hitsSet($fid, $num)
- {
- global $memObject;
- $hitskey = "fid_".$fid; //key
- $res = $memObject->get($hitskey );
- if(empty($res)) {
- $memObject->set($hitskey ,$num); //设置 fid_id=>num
- } else {
- $memObject->replace($hitskey , $num); //重置替换
- }
- $memObject->close(); //一定要记得关闭,否则 TIME_OUT 进程会越来越多
- }
- //获取点击数
- function hitsGet($fid)
- {
- global $memObject;
- $groupkey = "fid_".$fid; //key
- $res = $memObject->get($fid); //获取value
- $num = empty($res) ? '0' : $res;
- return $num;
- $memObject->close();
- }
- ?>