• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

03-PHP-memcached

原作者: [db:作者] 来自: [db:来源] 收藏 邀请
【安装memcached】
[安装 libevent]
$ tar zxvf libevent-2.0.20-stable.tar.gz
$ cd libevent-2.0.20-stable/
$ ./configure --prefix=/usr/local/libevent
$ make && make install
注:Mac下可能会出错:bufferevent_openssl.c:60:10: fatal error: 'openssl/bio.h' file not found,解决方案:

brew install openssl

brew link openssl --force

cp -R /usr/local/Cellar/openssl/1.0.2h_1/include/openssl ~/software/libevent-2.0.22-stable 

 
[安装memcached服务端]
$ tar zxvf memcached-1.4.39.tar.gz
$ ./configure --prefix=/usr/local/memcached --with-libevent=/usr/local/libevent
$ make && make install
 
[启动]
$ cd /usr/local/memcached
$ ./memcached -u root –d    #启动memcached
$ ps -ef |grep memcached     #查看memcached运行状态
 
【备注】设置memcached开机启动,vim打开/etc/rc.local在最后面写入:
/usr/local/memcached/bin/memcached -u root -d
 
[连接]
$telnet 127.0.0.1 11211
stats     --查看状态
version       --查看版本
set user 1 3000 10 --添加数据
get user  --获取数据
delete user    --删除数据
flush_all --清空所有

 

 
安装php-memcached扩展】
[安装 libmemcached]
$ tar zxvf libmemcached-1.0.18.tar.gz
$ cd libmemcached-1.0.18/
$ ./configure --prefix=/usr/local/libmemcached --with-memcached --enable-sasl
$ make && make install
注:Mac下可能会出错:error: use of undeclared identifier 'ntohll',解决方案:
1)编辑libmemcached/byteorder.cc文件
在 #include "libmemcached/byteorder.h" 下面增加以下内容:
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif

(
2)、编辑clients/memflush.cc文件 将两处 if (opt_servers == false) 替换成 if (opt_servers == NULL)
 
 
[安装 php-memcached扩展]
$ unzip php-memcached-php7.zip
$ cd php-memcached-php7/
$ /usr/local/php/bin/phpize
$ ./configure --enable-memcached --with-php-config=/usr/local/php/bin/php-config --with-libmemcached-dir=/usr/local/libmemcached --enable-memcached-sasl
$ make && make install

  安装完成后,在php.ini(/usr/local/php/php.ini) 后面添加 extension=memcached.so
 
 
 [PHP操作memcached]
<?php
$mem = new Memcached; //创建一个memcache对象
$mem->addServer('127.0.0.1', 11211) or die ("Could not connect"); //连接Memcached服务器
$mem->set('key', 'test'); //设置一个变量到内存中,名称是key 值是test
$val = $mem->get('key'); //从内存中取出key的值
echo $val;
?>

 

 
 
 
 
 
 
 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP动态输出svgz格式图片发布时间:2022-07-10
下一篇:
PHP 中巧用数组降低程序的时间复杂度发布时间:2022-07-10
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap