php连接memcached
先安装php的memcache扩展
创新互联建站是专业的大姚网站建设公司,大姚接单;提供成都网站设计、网站制作,网页设计,网站设计,建网站,PHP网站建设等专业做网站服务;采用PHP框架,可快速的进行大姚网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,专业的做网站团队,希望更多企业前来合作!
# 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
本文名称:php连接memcached
转载源于:http://pwwzsj.com/article/gscpde.html