Chinaunix首页 | 论坛 | 博客
  • 博客访问: 312783
  • 博文数量: 96
  • 博客积分: 230
  • 博客等级: 二等列兵
  • 技术积分: 722
  • 用 户 组: 普通用户
  • 注册时间: 2012-02-13 22:25
个人简介

心安处即吾乡!

文章分类

全部博文(96)

文章存档

2016年(1)

2014年(79)

2013年(7)

2012年(9)

我的朋友

分类: LINUX

2014-04-17 20:11:49

1.首先,关于memcache与memcached之间的区别联系,请参照博文【理解memcache的服务器端和客户端】
2.其次,php的memcache与memcached两种不同客户端扩展共用同一个服务端程序memcached,关于服务器端的memcached的安装与服务开启,请参照博文【开启php5的memcache扩展(UbuntuOS)】
一.服务器端
memcached安装需要libevent支持
二.客户端
1.memcache客户端:
下载地址:
安装PECL的memcache扩展
# tar -xzvf memcache-3.0.6.tgz (距离今天2012-01-11为止,最新版本)
# cd memcached-3.0.6/
# phpize(如果找不到运行whereis phpize,然后输入全路径)
# ./configure
# make
# make install
安装完成后会返回memcache.so文件生成的路径 如果未在php的extension标准路径下(phpinfo可查看),则cp至php的extension路径下
在php.ini中添加如下内容:
extension=memcache.so

2.memcached客户端:
下载地址:d
安装PECL的memcached扩展(需要libmemcached库支持)
# tar -xzvf memcached-2.0.0b2.tgz (距离今天2012-01-11为止,最新版本)
# cd memcached-2.0.0b2/
# phpize(如果找不到运行whereis phpize,然后输入全路径)
# ./configure
# make
# make install
安装完成后会返回memcached.so文件生成的路径 如果未在php的extension标准路径下(phpinfo可查看),则cp至php的extension路径下
在php.ini中添加如下内容:
extension=memcached.so

安装配置完成后重启apache后即可测试
-------------------------
# Test Install
-------------------------
# Create a file 'memcache_test.php' in your webroot and paste the following:

点击(此处)折叠或打开

  1. <?php
  2. $m = new Memcached();
  3. $m->addServer('localhost', 11211) or die ("Could not connect");

  4. $version = $m->getVersion();print_r($version);
  5. echo "
    \n"
    ;

  6. $tmp_object = new stdClass;
  7. $tmp_object->str_attr = 'test';
  8. $tmp_object->int_attr = 123;

  9. $m->set('key', $tmp_object, 10) or die ("Failed to save data at the server");
  10. echo "Store data in the cache (data will expire in 10 seconds)
    \n"
    ;

  11. $get_result = $m->get('key');
  12. echo "Data from the cache:
    \n"
    ;

  13. var_dump($get_result);
  14. ?>


# Test to see if the file renders in your browser

Cheers!
阅读(1148) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~