php安装memcached扩展

PHP教程评论749阅读模式

背景:在CenOS7.7下

1 编译、安装、测试

# 安装依赖包
yum -y install cyrus-sasl-devel
# 编译安装libmemcached
tar -zxvf libmemcached-1.0.18.tar.gz
cd libmemcached-1.0.18
./configure && make && make install && cd ..

# 为PHP的Memcached扩展生成configure文件
tar -zxvf memcached-2.2.0.tgz
(我实际使用了 memcached-3.1.5版本)
cd memcached-2.2.0
/usr/local/php/bin/phpize

# 编译安装PHP的Memcached扩展
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install && cd ..
# 在PHP的配置文件php.ini中加载Memcached扩展
vi /usr/local/php/lib/php.ini
# 添加如下配置
extension=/usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/memcached.so
# PHP-FPM重新加载配置
service php-fpm reload

# 测试Memcached
vi /data/www/test.php
<?php
# 连接Memcached服务器
$mem = new Memcached();
$mem->addServer('192.168.78.19', 11211);
# 保存数据(Key/Value形式,Key=UserName,Value=James)
$mem->set('UserName', 'James');
# 获取数据(根据Key=UserName,获得Value)输出结果:James
echo $mem->get('UserName');
?>

2 出现的问题
2.1 编译libmemcached(./configure)时报错
报错内容如下:文章源自爱尚资源教程网-https://www.23jcw.net/1178.html

clients/memflush.cc:42:22: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
if (opt_servers == false)
^~~~~
clients/memflush.cc:51:24: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
if (opt_servers == false)
^~~~~

原因:gcc版本比较高,不兼容。
解决方法:对源码略作修改。文章源自爱尚资源教程网-https://www.23jcw.net/1178.html

# 将clients/memflush.cc的42行和51行作如下修改:
int main(int argc, char *argv[])
{
  options_parse(argc, argv);

-  if (opt_servers == false)
+  if (!opt_servers)
   {
     char *temp;

-    if (opt_servers == false)
+    if (!opt_servers)
     {
       std::cerr << "No Servers provided" << std::endl;
       exit(EXIT_FAILURE);

然后再次make,编译通过。文章源自爱尚资源教程网-https://www.23jcw.net/1178.html

2.2 编译memcached-3.1.5报错

报错内容如下:文章源自爱尚资源教程网-https://www.23jcw.net/1178.html

configure: error: no, libmemcached built with sasl disabled. Run configure with --disable-memcached-sasl or update libmemcached with sasl support

添加--disable-memcached-sasl,再次编译通过:文章源自爱尚资源教程网-https://www.23jcw.net/1178.html

./configure --with-php-config=/usr/local/php/bin/php-config --disable-memcached-sasl
文章源自爱尚资源教程网-https://www.23jcw.net/1178.html文章源自爱尚资源教程网-https://www.23jcw.net/1178.html
相关文章
版权声明:文章图片资源来源于网络,如有侵权,请留言删除!!!
  • 温馨提示:如遇到资源下载不了,或者文章没有解决你的问题的,可以联系我们帮你处理!!!
  • 转载请务必保留本文链接:https://www.23jcw.net/1178.html

发表评论