安装php memcached扩展支持

需要安装的插件

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

https://launchpad.net/libmemcached/+download

先安装libmemcached

./configure –prefix=/usr/local/libmemcached  –with-memcached
make && make install

如果遇到libmemcached编译报错请看
libmemcached 编译错误

再安装php memcached扩展

先phpize
./configure –enable-memcache –with-php-config=/usr/local/php5/bin/php-config –with-libmemcached-dir=/usr/local/libmemcached
make
make install

–with-php-config请根据自己的php安装目录指定

然后找到php.ini 添加

extension_dir = “/usr/local/php5/lib/php/extensions/no-debug-non-zts-20060613/”
extension=memcache.so

附上一段测试代码

<!--?php $memcache = new Memcache; $memcache--->connect('127.0.0.1', 11211) or die ("Could not connect");
$version = $memcache->getVersion();
echo "Server's version: ".$version."\n";
$tmp_object = new stdClass;
$tmp_object->str_attr = 'test';
$tmp_object->int_attr = 123;
$memcache->set('key', $tmp_object, false, 10) or die ("Failed to save data at the server");
echo "Store data in the cache (data will expire in 10 seconds)\n";
$get_result = $memcache->get('key');
echo "Data from the cache:\n";
var_dump($get_result);
?>
  1. 暂无评论

  1. 暂无 Trackback

return top