CentOS环境PHP安装memcache扩展

安装memcache

yum install memcached  

 

安装libmemcached库

yum install libmemcached

PHP安装Memcache扩展

[email protected]] 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

[[email protected]] vim /etc/php.ini

#extension = /usr/lib64/php/modules/memcache.so

[[email protected]] service php-fpm reload

 启动

memcached -d -u root -p 11211

 测试:

CentOS环境PHP安装memcache扩展
<?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.http://www.cnblogs.com/wubaiqing/archive/2011/09/19/2181602.html

 

你可能感兴趣的:(memcache)