php的memcahce的扩展

18 篇文章 0 订阅

安装memcached需要libevent库的支持,由于memcache配置文件中对libevent的支持方式为–with-libevent=PATH       Specify path to libevent installation,此处就用源码安装的方式

服务端配置

下载 libevent

http://libevent.org/ 最新稳定版 libevent-2.0.16-stable.tar.gz

#tar zxvf libevent-2.0.16-stable.tar.gz

#cd libevent-2.0.16-stable

#./configure –prefix=/usr/local/libevent

#make; make install

下载memcahce服务器

http://memcached.org/ 最新稳定版本 memcached-1.4.10.tar.gz

#tar zxvf memcached-1.4.10.tar.gz 解压

#cd memcached-1.4.10

#./configure –prefix=/usr/local/memcached –with-libevent=/usr/local/libevent

#make; make install

客户端配置(php)

下载php的memcache扩展(源码方式安装)

http://pecl.php.net/package/memcache 最新版本 memcache-2.2.6.tgz

# tar zxf memcache-2.2.6.tgz
# cd memcache-2.2.6

# /usr/local/php/bin/phpize (这个是php的安装路径)生成configure文件

#./configure –enable-memcache=/usr/local/memcached –with-php-config=/usr/local/php/bin/php-config –with-apxs2==/usr/local/apache2/bin/apxs

#make; make install

安装完后会有类似这样的提示:

/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626

修改php.ini

extension_dir = “./”

修改为

extension_dir = “/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626″

并添加一行

extension = “memcache.so”

重启apache,使memcache有效

#service httpd restart

通过phpinfo 可以查看 php的memcache扩展是否装好

下面测试memcache服务器

<?php

$memcache = new Memcache;

$memcache->connect(‘localhost’, 12000) or die (“Could not connect”);

$version = $memcache->getVersion();

echo “Server’s version: “.$version.”<br/>\n”;

$tmp_object = new stdClass;

$tmp_object->str_attr = ‘test’;

$tmp_object->int_attr = 123;

$memcache->set(‘key’, $tmp_object, false, 10) or die (“Failed to save data at the server”);

echo “Store data in the cache (data will expire in 10 seconds)<br/>\n”;

$get_result = $memcache->get(‘key’);

echo “Data from the cache:<br/>\n”;

var_dump($get_result);


显示结果:

Server’s version: 1.4.10
Store data in the cache (data will expire in 10 seconds)
Data from the cache:
object(stdClass)#3 (2) { ["str_attr"]=> string(4) “test” ["int_attr"]=> int(123) }

memcache搭建完毕

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值