php memcached扩展下载地址
官网:http://pecl.php.net/package/memcache
memcahced下载地址
http://memcached.org/
libevent下载
http://libevent.org/
-----------------------------------------
安装libevent
[root@192 memcached]# tar -zxf libevent-2.1.8-stable.tar.gz
[root@192 memcached]# cd libevent-2.1.8-stable
[root@192 libevent-2.1.8-stable]# ./configure --prefix=/usr/local/libevent
[root@192 libevent-2.1.8-stable]# make && make install
---------------------------------------------------
安装memcached
[root@192 memcached]# tar -zxf memcached-1.5.6.tar.gz
[root@192 memcached]# cd memcached-1.5.6
[root@192 memcached-1.5.6]# ./configure --prefix=/usr/local/memcached --with-libevent=/usr/local/libevent
[root@192 memcached-1.5.6]# make && make install
-----------------------------------------------
安装PHP的memcache扩展
[root@192 memcached]# tar -zxf memcache-2.2.7.tgz
[root@192 memcached]# cd memcache-2.2.7
[root@192 memcache-2.2.7]# /usr/local/php5/bin/phpize
遇到报错
Cannot find autoconf. Please check your autoconf installation and the $PHP_AUTOCONF environment variable. Then, rerun this script.
解决办法
[root@192 autoconf-2.62]# yum install m4
[root@192 autoconf-2.62]# yum install autoconf
重新phpize
[root@192 memcache-2.2.7]# /usr/local/php5/bin/phpize
[root@192 memcache-2.2.7]# ./configure --enable-memcache --with-php-config=/usr/local/php5/bin/php-config --with-zlib-dir
[root@192 memcache-2.2.7]# make && make install
Installing shared extensions: /usr/local/php5/lib/php/extensions/no-debug-non-zts-20131226/
----------------------------------------------------
修改PHP配置文件支持memcahched
[root@192 memcache-2.2.7]# cd /etc/php5
[root@192 php5]# vi php.ini
把extension_dir = "./"修改为
extension_dir = "/usr/local/php5/lib/php/extensions/no-debug-non-zts-20131226/"
添加一行来载入memcache扩展:extension=memcache.so
----------------------------------------------------------
memcached的设置
添加到环境变量
[root@192 bin]# cd /etc/profile.d/
[root@192 profile.d]# vi memcached.sh
export PATH=$PATH:/usr/local/memcached/bin/
导出man帮助
[root@192 etc]# vi /etc/man_db.conf
MANPATH_MAP /usr/local/memcached /usr/local/memcached/share/man
------------------------------------------------------------------
测试
启动Memcache的服务器端:
memcached -d -m 10 -u root -l 127.0.0.1 -p 11211 -c 256 -P /tmp/memcached.pid
-d选项是启动一个守护进程,
-m是分配给Memcache使用的内存数量,单位是MB,我这里是10MB,
-u是运行Memcache的用户,我这里是root,
-l是监听的服务器IP地址,如果有多个地址的话,我这里指定了服务器的IP地址127.0.0.1,
-p是设置Memcache监听的端口,我这里设置了11211,最好是1024以上的端口,
-c选项是最大运行的并发连接数,默认是1024,我这里设置了256,按照你服务器的负载量来设定,
-P是设置保存Memcache的pid文件,我这里是保存在 /tmp/memcached.pid
2. 结束memcached进行
kill cat /tmp/memcached.pid
测试php的memcache扩展
<?php
$mem = new Memcache;
$mem->connect("192.168.12.201", 13001);
$mem->set('key','This is a test!', 0, 60);
$val = $mem->get('key');
echo $val;
?>
安装时候遇到的错误
Cannot find autoconf. Please check your autoconf installation and the $PHP_AUTOCONF environment variable. Then, rerun this script.
运行/usr/local/webserver/php/bin/phpize时出现:
Configuring for:
PHP Api Version: 20041225
Zend Module Api No: 20060613
Zend Extension Api No: 220060519
Cannot find autoconf. Please check your autoconf installation and the
$PHP_AUTOCONF environment variable. Then, rerun this script.
根据网上的解决办法是:
# cd /usr/src
# wget http://ftp.gnu.org/gnu/m4/m4-1.4.9.tar.gz
# tar -zvxf m4-1.4.9.tar.gz
# cd m4-1.4.9/
# ./configure && make && make install
# cd ../
# wget http://ftp.gnu.org/gnu/autoconf/autoconf-2.62.tar.gz
# tar -zvxf autoconf-2.62.tar.gz
# cd autoconf-2.62/
# ./configure && make && make install
更简单的办法
# yum install m4
# yum install autoconf
官网:http://pecl.php.net/package/memcache
memcahced下载地址
http://memcached.org/
libevent下载
http://libevent.org/
-----------------------------------------
安装libevent
[root@192 memcached]# tar -zxf libevent-2.1.8-stable.tar.gz
[root@192 memcached]# cd libevent-2.1.8-stable
[root@192 libevent-2.1.8-stable]# ./configure --prefix=/usr/local/libevent
[root@192 libevent-2.1.8-stable]# make && make install
---------------------------------------------------
安装memcached
[root@192 memcached]# tar -zxf memcached-1.5.6.tar.gz
[root@192 memcached]# cd memcached-1.5.6
[root@192 memcached-1.5.6]# ./configure --prefix=/usr/local/memcached --with-libevent=/usr/local/libevent
[root@192 memcached-1.5.6]# make && make install
-----------------------------------------------
安装PHP的memcache扩展
[root@192 memcached]# tar -zxf memcache-2.2.7.tgz
[root@192 memcached]# cd memcache-2.2.7
[root@192 memcache-2.2.7]# /usr/local/php5/bin/phpize
遇到报错
Cannot find autoconf. Please check your autoconf installation and the $PHP_AUTOCONF environment variable. Then, rerun this script.
解决办法
[root@192 autoconf-2.62]# yum install m4
[root@192 autoconf-2.62]# yum install autoconf
重新phpize
[root@192 memcache-2.2.7]# /usr/local/php5/bin/phpize
[root@192 memcache-2.2.7]# ./configure --enable-memcache --with-php-config=/usr/local/php5/bin/php-config --with-zlib-dir
[root@192 memcache-2.2.7]# make && make install
Installing shared extensions: /usr/local/php5/lib/php/extensions/no-debug-non-zts-20131226/
----------------------------------------------------
修改PHP配置文件支持memcahched
[root@192 memcache-2.2.7]# cd /etc/php5
[root@192 php5]# vi php.ini
把extension_dir = "./"修改为
extension_dir = "/usr/local/php5/lib/php/extensions/no-debug-non-zts-20131226/"
添加一行来载入memcache扩展:extension=memcache.so
----------------------------------------------------------
memcached的设置
添加到环境变量
[root@192 bin]# cd /etc/profile.d/
[root@192 profile.d]# vi memcached.sh
export PATH=$PATH:/usr/local/memcached/bin/
导出man帮助
[root@192 etc]# vi /etc/man_db.conf
MANPATH_MAP /usr/local/memcached /usr/local/memcached/share/man
------------------------------------------------------------------
测试
启动Memcache的服务器端:
memcached -d -m 10 -u root -l 127.0.0.1 -p 11211 -c 256 -P /tmp/memcached.pid
-d选项是启动一个守护进程,
-m是分配给Memcache使用的内存数量,单位是MB,我这里是10MB,
-u是运行Memcache的用户,我这里是root,
-l是监听的服务器IP地址,如果有多个地址的话,我这里指定了服务器的IP地址127.0.0.1,
-p是设置Memcache监听的端口,我这里设置了11211,最好是1024以上的端口,
-c选项是最大运行的并发连接数,默认是1024,我这里设置了256,按照你服务器的负载量来设定,
-P是设置保存Memcache的pid文件,我这里是保存在 /tmp/memcached.pid
2. 结束memcached进行
kill cat /tmp/memcached.pid
测试php的memcache扩展
<?php
$mem = new Memcache;
$mem->connect("192.168.12.201", 13001);
$mem->set('key','This is a test!', 0, 60);
$val = $mem->get('key');
echo $val;
?>
安装时候遇到的错误
Cannot find autoconf. Please check your autoconf installation and the $PHP_AUTOCONF environment variable. Then, rerun this script.
运行/usr/local/webserver/php/bin/phpize时出现:
Configuring for:
PHP Api Version: 20041225
Zend Module Api No: 20060613
Zend Extension Api No: 220060519
Cannot find autoconf. Please check your autoconf installation and the
$PHP_AUTOCONF environment variable. Then, rerun this script.
根据网上的解决办法是:
# cd /usr/src
# wget http://ftp.gnu.org/gnu/m4/m4-1.4.9.tar.gz
# tar -zvxf m4-1.4.9.tar.gz
# cd m4-1.4.9/
# ./configure && make && make install
# cd ../
# wget http://ftp.gnu.org/gnu/autoconf/autoconf-2.62.tar.gz
# tar -zvxf autoconf-2.62.tar.gz
# cd autoconf-2.62/
# ./configure && make && make install
更简单的办法
# yum install m4
# yum install autoconf