查看“Php连接有密码的memcached服务”的源代码
←
Php连接有密码的memcached服务
跳到导航
跳到搜索
因为以下原因,您没有权限编辑本页:
您所请求的操作仅限于该用户组的用户使用:
用户
您可以查看与复制此页面的源代码。
php连接有密码的 memcached服务 =我的环境 = <pre>ubuntu 18.04 xampp 7.3.12 有密码的memcached服务 相关信息 '192.168.10.214:11211'), 'memcached', 'RV3kEjX5Ug5ufTKO'</pre> =ins sasl 库= <pre> apt-get install -y \ libevent-dev \ libsasl2-2 \ sasl2-bin \ libsasl2-2 \ libsasl2-dev \ wget \ pwgen \ gcc \ make \ libsasl2-modules</pre> =ins libmemcached= <pre> wget -c https://launchpad.net/libmemcached/1.0/1.0.18/+download/libmemcached-1.0.18.tar.gz tar xvf libmemcached-1.0.18.tar.gz cd libmemcached-1.0.18/ ./configure --prefix=/usr/local/libmemcached --enable-sasl Ubuntu 18.04 LTS使用GCC 7.3版本,编译libmemcached失败。 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) ^~~~~ </pre> 编译前需要打个补丁,参见: https://bugs.launchpad.net/libmemcached/+bug/1663985 https://src.fedoraproject.org/cgit/rpms/libmemcached.git/plain/libmemcached-build.patch <pre> wget https://src.fedoraproject.org/rpms/libmemcached/raw/HEAD/f/libmemcached-build.patch libmemcached-1.0.18# patch -p1 < libmemcached-build.patch make -j3 && make install </pre> = ins php memcached = <pre> memcached PHP extension for interfacing with memcached via libmemcached library wget -c https://pecl.php.net/get/memcached-3.1.5.tgz apt install m4 autoconf tar xvf memcached-3.1.5.tgz cd /opt/memcached-3.1.5/ /opt/lampp/bin/phpize ./configure --with-libmemcached-dir=/usr/local/libmemcached --enable-memcached-sasl --with-php-config=/opt/lampp/bin/php-config make -j3 make install Installing shared extensions: /opt/lampp/lib/php/extensions/no-debug-non-zts-20180731/ vim /opt/lampp/etc/php.ini ; add extension=memcached.so memcached.use_sasl = 1 检验 /opt/lampp/bin/php -m | grep mem memcached 或者直接 phpinfo </pre> =PHP 代码示例= <pre> 示例1:基本的连接云数据库 Memcache 及 set/get 操作 <?php $connect = new Memcached; //声明一个新的memcached链接 $connect->setOption(Memcached::OPT_COMPRESSION, false); //关闭压缩功能 $connect->setOption(Memcached::OPT_BINARY_PROTOCOL, true); //使用binary二进制协议 $connect->setOption(Memcached::OPT_TCP_NODELAY, true); //重要,php memcached有个bug,当get的值不存在,有固定40ms延迟,开启这个参数,可以避免这个bug $connect->addServer('192.168.10.214', 11211); //添加memcached地址及端口号 $connect->setSaslAuthData('memcached', 'RV3kEjX5Ug5ufTKO'); //S帐号密码进行鉴权,如已开启免密码功能,则无需此步骤 $connect->set("hello", " hey evan world"); echo 'hello: ',$connect->get("hello"); $connect->quit(); ?> 打开浏览器 hello: hey evan world </pre> =troubleshooting= <pre> 装cyrus-sasl-devel软件包然后重新编译libmemcached。 重新libme 再安装一次吧 要先打包时一样安装 sasl之类的 configure: error: no, libmemcached built with sasl disabled. Run configure with --disable-memcached-sasl or update libmemcached with sasl support </pre> =see also= [https://help.aliyun.com/document_detail/48432.html aliyun文档PHP: memcached] https://www.php.net/manual/en/book.memcached.php
返回至
Php连接有密码的memcached服务
。
导航菜单
个人工具
登录
名字空间
页面
讨论
变种
视图
阅读
查看源代码
查看历史
更多
搜索
导航
首页
我的导航
关于我
shell
python
ops
linuxchina.net
blog.linuxchina
最近更改
随机页面
帮助
工具
链入页面
相关更改
特殊页面
页面信息