PHP5.4.x和Memcache的版本不兼容问题

下载目前最新的PHP5.4.8编译后(fpm),使用sudo apt-get install memcached安装memcache服务,再使用Pecl:http://www.ln.la/473/pecl-pear-php-extensions.html安装memcache(sudo pecl install memcache)PHP扩展,编译后memcache.so在/usr/lib/php5/20090626/中,在PHP.ini添加好extension,重启phpfpm(不是重启nginx),出现下面的错误信息:

1 Gracefully shutting down php-fpm . done

2 Starting php-fpm [25-Oct-2012 12:04:02] NOTICE:

3 PHP message: PHP Warning: PHP Startup: memcache: Unable to initialize module

4 Module compiled with module API=20090626

5 PHP compiled with module API=20100525

6 These options need to match

编译PHP使用的PHP核心版本是20100525,而Pecl里面的Memcache是使用20090626版本编译的,版本不一致导致PHP无法启用memcache.so库。解决方法是卸载掉Pecl方式安装的Memcache,去http://pecl.php.net/package/memcache下载源码包自己编译。

1 ##卸载memcache

2 sudo pecl uninstall memcache

3 phpize

4 ./configure –enable-memcache –with-php-conf=/usr/local/php/bin/php-config

5 make

6 make install

启动memcached服务:memcached -d -m 256 -p 11211。测试脚本:OK。

1 $mem = new Memcache;

2 $mem->connect(‘127.0.0.1’,11211);

3 $mem->set(‘lnla’,’blog’);

4 var_dump( $mem->get(‘lnla’) );