基于libmemcached,php扩充memcached的安装

WBOY
Release: 2016-06-13 11:01:08
Original
709 people have browsed it

基于libmemcached,php扩展memcached的安装

一,为什么要装memcached扩展

memcached的1.2.4及以上增加了CAS(Check and Set)协议,对于同一key的多进行程的并发处理问题。这种情况其实根数据库很像,如果同时有几个进程对同一个表的同一数据进行更新的话,那会不会打架呢,哈哈。数据库里面可以锁定整张表,也可以锁定表里面一 行的功能,其实memcached加入的CAS根这个差不多。

php的扩展memcache,不支持cas,所以我们要装memcached扩展,memcached扩展是基于libmemcached,所以要先安装libmemcached

?

二,查看memcahced的版本信息

telnet 127.0.0.1 12000
stats
你会看到有以下信息
STAT pid 15322
STAT uptime 1885
STAT time 1279455772
STAT version 1.2.8
STAT pointer_size 32
如果版本过低,考虑重新装一下

退出telnet ,ctrl + ] 然后在按q就行了。

三,安装所要软件

wget http://launchpad.net/libmemcached/1.0/0.42/+download/libmemcached-0.42.tar.gz

wget http://pecl.php.net/get/memcached-1.0.2.tgz

memcached的官方网站 http://www.memcached.org/

四,安装libmemcached

tar zxvf libmemcached-0.42.tar.gz
cd libmemcached-0.42
./configure –prefix=/usr/local/libmemcached? –with-memcached
make && make install

安装要注意的问题:

1,? 安装过程中不要忘了,–with-memcached,不然会提示你

checking for memcached… no
configure: error: “could not find memcached binary”

2,你的memcached是不是1.2.4以上的,如果不是会提示你

clients/ms_thread.o: In function `ms_setup_thread’:
/home/zhangy/libmemcached-0.42/clients/ms_thread.c:225: undefined reference to `__sync_fetch_and_add_4′
clients/ms_thread.o:/home/zhangy/libmemcached-0.42/clients/ms_thread.c:196: more undefined references to `__sync_fetch_and_add_4′ follow
collect2: ld returned 1 exit status
make[2]: *** [clients/memslap] Error 1
make[2]: Leaving directory `/home/zhangy/libmemcached-0.42′

解决办法是–disable-64bit CFLAGS=”-O3 -march=i686″,如果不用这个64位的long型数据,我想php扩展memcached,memcache也就没什么区别了,装memcached也就没什么意思了。

五,php的扩展memcached的安装

tar zxvf memcached-1.0.2.tar.gz
cd memcached-1.0.2
/usr/local/php/bin/phpize
./configure –enable-memcached –with-php-config=/usr/local/php/bin/php-config –with-libmemcached-dir=/usr/local/libmemcached
./configure –prefix=/usr/local/phpmemcached? –with-memcached
make && make install

vi /usr/local/php/lib/php.ini

加上extension=memcached.so重起一下服务就可以了.

?

转载:http://blog.51yip.com/php/928.html

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!