pecl memcached和memcache for PHP的比较

jackxiang 2010-9-4 21:00 | |
获取libmemcached包

http://tangent.org/552/libmemcached.html

右下角有个source

下载

./configure


configure: error: “could not find memcached binary”

http://memcached.org/

下载memcache..

./configure

make && make install

http://monkey.org/~provos/libevent/ (可能需要libevent)

安装了memcached以后,继续configure libmemcached

./configure

make && make install

下载PHP memcached 支持

http://pecl.php.net/package/memcached

~phpbin/phpize

./configure –with-php-config=~phpbin/php-config

make && make install

改了php.ini后

phpinfo()输出:

memcached

memcached support enabled

Version 1.0.0

libmemcached version 0.37

Session support yes

igbinary support no

addServer(’10.10.10.50′, 11311);

function microtime_float()

{

list($usec, $sec) = explode(” “, microtime());

return ((float)$usec + (float)$sec);

}

$time_start = microtime_float();

for($i=0;$i<10000;$i++) { $m->set(‘int’, 99);

$m->set(‘string’, ‘a simple string’);

$m->set(‘array’, array(11, 12));

/* expire ‘object’ key in 5 minutes */

$m->set(‘object’, new stdclass, time() + 300);

//$m->get(‘int’);

//$m->get(‘string’);

//$m->get(‘array’);

//$m->get(‘object’);

}

$time_end = microtime_float();

$time = $time_end – $time_start;

echo “Did nothing in $time seconds\n”;

把第一行memcache改成memecached就能改了

我的实际测试结果

1万次读写 memcache:memcached 12:11

1万次只写,memcache:memcached 7:5

1万次只读 memcache:memcached 5.1:4.6

差距不大,而且memcached读取’object’这个key的时候居然报错了 Warning: Memcached::get(): unknown payload type in

这个应该是memcache写入的stdclass模式和memcached写入的格式不同,所以导致memcached读的时候出了问题。

总的来说libmemcached是全面胜出的,考虑到libmemcached还提供更多的接口,还是准备更换了!

libenv:: http://www.monkey.org/~provos/libevent/

wget http://www.monkey.org/~provos/libevent-1.4.13-stable.tar.gz

tar -zxvf libevent-1.4.13-stable.tar.gz

cd libevent-1.4.13-stable

./configure && make && make install

cd ..

tar -zxvf memcached-1.4.4.tar.gz

cd memcached-1.4.4

./configure && make && make install

cd ..

tar -zxvf libmemcached-0.37.tar.gz

cd libmemcached-0.37

./configure && make && make install

cd ..

tar -zxvf memcached-1.0.0.tgz

cd memcached-1.0.0

/usr/local/php/bin/phpize && ./configure –with-php-config=/usr/local/php/bin/php-config && make && make install

cd ..

vi /usr/local/php/etc/php.ini


来源:http://blog.fabrichina.net/archives/157

作者:jackxiang@向东博客 专注WEB应用 构架之美 --- 构架之美,在于尽态极妍 | 应用之美,在于药到病除
地址:http://jackxiang.com/post/3471/
版权所有。转载时必须以链接形式注明作者和原始出处及本声明!

评论列表
发表评论

昵称

网址

电邮

打开HTML 打开UBB 打开表情 隐藏 记住我 [登入] [注册]