您的位置:首页 > 数据库 > Memcache

CentOS环境PHP安装memcache扩展

2015-06-05 10:09 656 查看
安装memcache

yum install memcached


安装libmemcached库

yum install libmemcached


PHP安装Memcache扩展

root@blog.phpha.com] wget -c http://pecl.php.net/get/memcache-3.0.8.tgz [root@blog.phpha.com] tar -zxvf memcache-3.0.8.tgz
[root@blog.phpha.com] cd memcache-3.0.8
[root@blog.phpha.com] /usr/local/php/bin/phpize
[root@blog.phpha.com]  ./configure  -with-php-config=/usr/bin/php-config -with-zlib-dir
[root@blog.phpha.com] make && make install
#Installing shared extensions:     /usr/lib64/php/modules/
#/usr/lib64/php/modules/memcache.so
[root@blog.phpha.com] vim /etc/php.ini
#extension = /usr/lib64/php/modules/memcache.so
[root@blog.phpha.com] service php-fpm reload


启动

memcached -d -u root -p 11211


测试:

<?php

$mem = new Memcache;

$mem->addServer("localhost",11211);

echo "Version:".$mem->getVersion();

class testClass{

private $str_attr;
private $int_attr;

public function __construct($str,$int)
{
$this->str_attr = $str;
$this->int_attr = $int;
}

public function set_str($str)
{
$this->str_attr = $str;
}
public function set_int($int)
{
$this->int_attr = $int;
}

public function get_str()
{
return $this->str_attr;
}
public function get_int()
{
return $this->int_attr;
}
}

$test = new testClass("hell world",1123);
$mem->set("key",$test,false,1000);

var_dump($mem->get("key"));

$test_array = array("index_1"=>"hello","index_2"=>"world");

$mem->set("array_test",$test_array,false);

var_dump($mem->get("array_test"));

?>


View Code

问题:

1.找不到php-config

find / -name php-config


2.找不到 ZLIB memcache support requires ZLIB

yum install zlib-devel


3.can't run as root without the -u switch

memecached -u root start


参考:

centos 为php安装memcache.http://blog.csdn.net/php_boy/article/details/6880488

CentOS环境PHP安装memcache扩展.http://blog.phpha.com/archives/1554.html

Centos安装Memcache./article/5268589.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: