zoukankan      html  css  js  c++  java
  • CentOS环境PHP安装memcache扩展

    安装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.http://www.cnblogs.com/wubaiqing/archive/2011/09/19/2181602.html

  • 相关阅读:
    Seaborn相关
    Matplot相关(二)——统计图
    PAT 甲级真题
    数学题一
    Codeforces Round #467 (Div. 2)
    国庆 Day1
    [NOIP 2005] 运输计划
    dp专题练习
    YBT 2.4 AC自动机
    [模板]树链剖分
  • 原文地址:https://www.cnblogs.com/ccdc/p/4553921.html
Copyright © 2011-2022 走看看