安装PHP memcached扩展
引用
pecl.php.net有两个memcache扩展:
memcache memcached extension
memcached PHP extension for interfacing with memcached via libmemcached library
memcache memcached extension
memcached PHP extension for interfacing with memcached via libmemcached library
memcached 的版本比较新,而且使用的是 libmemcached 库。libmemcached 被认为做过更好的优化,应该比 php only 版本的 memcache 有着更高的性能。所以这里安装的是memcached(假设php5.4已经安装在在/usr/local/php).
1. 安装依赖库
https://launchpad.net/libmemcached/1.0/1.0.4/+download/libmemcached-1.0.4.tar.gz
- tar -xzvf libmemcached-1.0.4.tar.gz
- cd libmemcached-1.0.4
- ./configure
- make
- make install
2.安装memcached
http://pecl.php.net/get/memcached-2.0.1.tgz下载,安装指令:
- tar vxzf memcached-2.0.1.tgz
- cd memcache-2.0.1
- phpize
- ./configure --enable-memcache --with-php-config=/usr/local/php/bin/php-config
- make
- make install
装完后,最后显示Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/,在该目录下生成memcached.so,将其复制到php.ini的extension_dir指向的目录。修改php.ini增加行extension = memcached.so重启apache,再到页面上打开phpinfo信息页面,看看memcached扩展是否安装成功了。
写个测试看看
- <?php
- $m = new Memcached();
- $m->addServer('localhost', 11211);
- $m->set('username', 'Allen');
- var_dump($m->get('username'));
- ?>
转载请注明原处