Chinaunix首页 | 论坛 | 博客
  • 博客访问: 192289
  • 博文数量: 43
  • 博客积分: 366
  • 博客等级: 一等列兵
  • 技术积分: 427
  • 用 户 组: 普通用户
  • 注册时间: 2011-10-17 14:03
文章分类

全部博文(43)

文章存档

2018年(2)

2017年(5)

2016年(2)

2015年(3)

2014年(9)

2013年(5)

2012年(8)

2011年(9)

我的朋友

分类: LINUX

2011-12-26 20:53:47

参考该文档:http://meizhini.iteye.com/blog/185165(memcached php-memcache 的安装及使用)

1、yum install libevent libevent-devel zlib-devel
2、yum install gcc gcc-c++
3、下载linux的memcache:
   ./configure --prefix=/usr/lib/
   make;make install
   启动:memcached -d -m 128 -p 11211 -u www-data
4、下载memcache对php的pecl扩展:
   cd memcache-xxx
   phpize
   ./configure --enable-memcache --with-php-config=/usr/bin/php-config --with-zlib-dir
   make; make install
   修改/etc/php.ini 修改 extension-dir="/usr/lib/php/modules/"(根据情况填写) 增加extension="memcache.so"
5、service httpd restart

测试,:
set:
        $mem = new Memcache;
        $mem->connect("127.0.0.1", 11211) or die("could not connect");
        $tmp_object = new stdClass; // 任何类型亦可,如int,string等等
        $tmp_object->str_attr = 'test';
        $tmp_object->int_attr = 123;

        $mem->set('key', $tmp_object, false, 100) or die ("Failed to save data at the server");
        echo "Store data in the cache (data will expire in 100 seconds)";

      
?>
get:
        $mem = new Memcache;
        $mem->connect("127.0.0.1", 11211) or die("could not connect");
        $get_result = $mem->get('key');
        echo "Data from the cache:\n";
        var_dump($get_result);
?>

可以到别的服务器尝试,不过要记着打开iptables的限制

linux的memcached的相关参数:
/usr/bin/memcached -d -m 128 -l 192.168.1.117 -p 11211 -u httpd
参数解释:
            -d 以守护程序(daemon)方式运行 memcached;
            -m 设置 memcached 可以使用的内存大小,单位为 M;
            -l 设置监听的 IP 地址,如果是本机的话,通常可以不设置此参数;
            -p 设置监听的端口,默认为 11211,所以也可以不设置此参数;
            -u 指定用户,如果当前为 root 的话,需要使用此参数指定用户。 当然,还有其它参数可以用,man memcached 一下就可以看到了。

php的memcache的相关参数:
通过phpinfo()中的memcache项查看,均可以在php.ini中设置
阅读(809) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~