php连接memcached
先安装php的memcache扩展
# wget http://www.lishiming.net/data/p_w_upload/forum/memcache-2.2.3.tgz
# tar zxf memcache-2.2.3.tgz
# cd memcache-2.2.3
# /usr/local/php/bin/phpize
# ./configure --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-20090626/
把这个记住,然后修改php.ini,把 extension_dir = "./" 修改为extension_dir = "/usr/local/servers/php5/lib/php/extensions/no-debug-non-zts-20090626/"
或者指定新的位置,我以下是指定新的位置
并添加一行extension="memcache.so"
[root@localhost memcache-2.2.3]# make install
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/
[root@localhost memcache-2.2.3]# ls /usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/
memcache.so
[root@localhost memcache-2.2.3]# vim /usr/local/php/etc/php.ini
[root@localhost memcache-2.2.3]# ls /usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/
memcache.so
将memcache.so拷贝到/usr/local/php/ext 下
[root@localhost memcache-2.2.3]# mkdir /usr/local/php/ext #创建目录
[root@localhost memcache-2.2.3]# cp /usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/memcache.so /usr/local/php/ext/
[root@localhost memcache-2.2.3]# ls !$
ls /usr/local/php/ext/
memcache.so
添加路径
[root@localhost memcache-2.2.3]# vim /usr/local/php/etc/php.ini
检测添加memcached模块是否添加成功
[root@localhost memcache-2.2.3]# /usr/local/php/bin/php -m|grep memcache
memcache
测试能否连接memcached
[root@localhost memcache-2.2.3]# curl www.apelearn.com/study_v2/.memcache.txt > 1.php 2>/dev/null
下载一个1.php文件
[root@localhost memcache-2.2.3]# /usr/local/php/bin/php 1.php
Get key1 value: This is first value
Get key1 value: This is replace value
Get key2 value: Array
(
[0] => aaa
[1] => bbb
[2] => ccc
[3] => ddd
)
Get key1 value:
Get key2 value:
[root@localhost memcache-2.2.3]#
[root@localhost memcache-2.2.3]# /usr/local/php/bin/phpize
Configuring for:
PHP Api Version: 20090626
Zend Module Api No: 20090626
Zend Extension Api No: 220090626
Cannot find autoconf. Please check your autoconf installation and the
$PHP_AUTOCONF environment variable. Then, rerun this script.
此时没有生成configure文件。
解决方法:
# 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