Linux 安装包4个:
1:libevent-2.0.22-stable.tar.gz(网上有说系统自备,然我的Centos6.5并木有)
2:memcached-1.4.15 .tar.gz(这个是memcached的客户端)3:libmemcached-1.0.4.tar.gz
4:memcache-3.0.8.tgz(生成php 扩展)
四个文件解压 tar zxvf ***
一、安装libevent
# cd libevent-2.0.22-stable
# ./configure --prefix=/usr/local/libevent/
# make && make install
二、安装memcached
# cd memcached-1.4.15.tar.gz
# ./configure --prefix=/usr/local/memcache --with-libevent=/usr/local/libevent
# make && make install
# cp scripts/memcached.sysv /etc/init.d/memcached
并且修改如下代码(就是修改memcache的路径)
chown $USER /usr/local/memcache/bin/memcached
daemon /usr/local/memcache/bin/memcached -d -p $PORT -u $USER -m $CACHESIZE -c $MAXCONN -P /var/run/memcached/memcached.pid $OPTIONS
启动memcached 服务
# service memcached start
三、安装libmemcached
# cd libmemcached-1.0.4.tar.gz
# ./configure --prefix=/usr/local/memcached --with-libevent=/usr/local/libevent
# make && make install
四、安装memcache
# cd memcache-3.0.8
# /usr/local/php/bin/phpize
# ./configure --with-php-config=/usr/local/php/bin/php-config --enable-memcache
# make && make install
安装完后会提示扩展安装在哪
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-zts-20131226/
在php.ini文件里的Dynamic Extensions后面添加
extension=/usr/local/php/lib/php/extensions/no-debug-zts-20131226/memcache.so
重启服务器,phpinfo后,就会看见里面多了memcache的内容
PHP测试代码
<?php $memcache = new Memecache; $memcache->connect("127.0.0.1", 11211) or die("Connected failed!");//连接memcache服务器 $version = $memcache->getVersion();//获取memcache版本 $memcache->set('test', 'Hello world', 0, 600); $memcache_get = $memcache->get('test'); echo "Memcache version is $version<br/>"; echo "Memecache data test value: $memcache_get"; ?>