Memcache(内存缓存):在内存中维护巨大的hash表,
Hash表结构
Key | Value |
myString | 字符串类型的数据 |
Myobject | 对象类型的数据 |
Myarray | 数组类型的数据 |
Memcache的工作原理
Memcache在Linux下的安装:
安装memcache之前先安装一个支持各种事件的库文件 libevent
Libevent有两种安装方式:
yum 安装
yum –y install libevent
源码安装:
tar -zxvvf libevent*.tar.gz
cd libevent*/
./configure–prefix=/usr/local/libevent/
Make&& make install
安装完libevent库后 安装memcache
Wget http://www.memcached.org/files/memcached-1.4.21.tar.gz
tar–zxvf memcached-1.4.21.tar.gz
cd memcached-1.4.21/
#yum 安装libevent用:
./configure–prefix=/usr/local/memcache –with-libevent=/usr/lib/
#源码安装用:
./configure –prefix=/usr/local/memcache –with-libevent=/usr/local/libevent/
Make && make install
#安装完memcache后启动
/usr/local/memcahe/bin/memcached -d -m128 –l 192.168.1.124 –p 11211 –u root
-d: 启动进程
-m 128 : 指定memcache管理的内存大小
-l:指定memcache服务器地址
-p:监听的端口
-uroot 用root用户运行memcache
停止memcache kill “cat /tmp/memcache.pid ” 或 killall memcached
安装php memcache的扩展库:
在http://pecl.php.net/package/memcache 选择相应想要下载的memcache版本。、
#tar vxzf memcache-2.2.6.tgz
# cd memcache-2.2.6
# /usr/local/php/bin/phpize
# ./configure --enable-memcache --with-php-config=/usr/local/php/bin/php-config
# make
# make install
修改php配置文件:
Vi /usr/local/php/etc/php.ini
重启Apache
/usr/local/apache/bin/apachectl restart
访问 PHPinfo文件结果如图: