欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  php教程

php的memcached扩展

程序员文章站 2024-04-04 20:59:11
...

1。安装libmemcached 下载 libmemcached1.0.16: wget https://launchpad.net/libmemcached/1.0/1.0.16/download/libmemcached-1.0.16.tar.gz tar -xzflibmemcached-1.0.16.tar.gz ./configure -prefix=/usr/local/libmemcached -with-memcached=/usr/local/

1。安装libmemcached

下载 libmemcached1.0.16:

wget https://launchpad.net/libmemcached/1.0/1.0.16/+download/libmemcached-1.0.16.tar.gz

tar -xzf libmemcached-1.0.16.tar.gz

./configure -prefix=/usr/local/libmemcached -with-memcached=/usr/local/memcached/bin/memcached

make

出现如下错误

make -j3  all-am
make[1]: Entering directory `/root/soft/libmemcached-1.0.16'
  CXX      libhashkit/libmemcached_libmemcached_la-aes.lo
  CXX      libhashkit/libmemcached_libmemcached_la-algorithm.lo
  CXX      libhashkit/libmemcached_libmemcached_la-behavior.lo
  CXX      libhashkit/libmemcached_libmemcached_la-crc32.lo
  CXX      libhashkit/libmemcached_libmemcached_la-digest.lo
  CXX      libhashkit/libmemcached_libmemcached_la-encrypt.lo
  CXX      libhashkit/libmemcached_libmemcached_la-fnv_32.lo
  CXX      libhashkit/libmemcached_libmemcached_la-fnv_64.lo
  CXX      libhashkit/libmemcached_libmemcached_la-function.lo
  CXX      libhashkit/libmemcached_libmemcached_la-has.lo
  CXX      libhashkit/libmemcached_libmemcached_la-hashkit.lo
  CXX      libhashkit/libmemcached_libmemcached_la-jenkins.lo
  CXX      libhashkit/libmemcached_libmemcached_la-ketama.lo
  CXX      libhashkit/libmemcached_libmemcached_la-md5.lo
  CXX      libhashkit/libmemcached_libmemcached_la-murmur.lo
  CXX      libhashkit/libmemcached_libmemcached_la-murmur3.lo
  CXX      libhashkit/libmemcached_libmemcached_la-one_at_a_time.lo
  CXX      libhashkit/libmemcached_libmemcached_la-murmur3_api.lo
  CXX      libhashkit/libmemcached_libmemcached_la-rijndael.lo
  CXX      libhashkit/libmemcached_libmemcached_la-str_algorithm.lo
  CXX      libhashkit/libmemcached_libmemcached_la-strerror.lo
  CXX      libhashkit/libmemcached_libmemcached_la-string.lo
  CXX      libhashkit/libmemcached_libmemcached_la-nohsieh.lo
  CXX      libmemcached/libmemcached_libmemcached_la-allocators.lo
  CXX      libmemcached/libmemcached_libmemcached_la-analyze.lo
In file included from ./libmemcached/common.h:114,
                 from libmemcached/analyze.cc:1:
./libmemcached-1.0/memcached.h:46:27: error: tr1/cinttypes: No such file or directory
In file included from ./libmemcached/common.h:114,
                 from libmemcached/allocators.cc:38:
./libmemcached-1.0/memcached.h:46:27: error: tr1/cinttypes: No such file or directory
make[1]: *** [libmemcached/libmemcached_libmemcached_la-analyze.lo] 错误 1
make[1]: *** 正在等待未完成的任务....
make[1]: *** [libmemcached/libmemcached_libmemcached_la-allocators.lo] 错误 1
make[1]: Leaving directory `/root/soft/libmemcached-1.0.16'
make: *** [all] 错误 2

经查,发现是gcc版本问题

于是先更新gcc版本

yum install gcc44 gcc44-c++ libstdc++44-devel

export CC=/usr/bin/gcc44

export CXX=/usr/bin/g++44


重新执行libmemcached 的 configure:

./configure -prefix=/usr/local/libmemcached -with-memcached=/usr/local/memcached/bin/memcached

make

make install

成功了


2。安装php的memcached扩展

cd memcached-1.4.5;

执行了几次/usr/local/php/bin/phpize,都报如下错误

Cannot find config.m4. 
Make sure that you run '/usr/local/php/bin/phpize' in the top level source directory of the module

后来发现这个不是php的memcached的扩展目录,然后找到memcached的php扩展目录memcached-1.0.2,苍天,我哪儿知道这个是memcached的php扩展目录啊,我还以为是低版本的memcached软件的源代码目录呢。


cd memcached-1.0.2;

执行

/usr/local/php/bin/phpize

世界变得美好了,先把结果拷贝到一个记事本里

然后执行./configure --with-php-config=/usr/local/php/bin/php-config --with-libmemcached-dir=/usr/local/libmemcached

命运依然多舛,又报错

make: *** [php_memcached.lo] 错误 1

发现是libmemcached版本过高,换低版本

然后继续configure,make ,make install

成功,真不容易

php的memcached扩展


然后在php.ini中增加extension = "memcached.so"

重启php-fpm和webserver(我这边用的是nginx)