zoukankan      html  css  js  c++  java
  • 03-PHP-memcached

    【安装memcached】
    [安装 libevent]
    $ tar zxvf libevent-2.0.20-stable.tar.gz
    $ cd libevent-2.0.20-stable/
    $ ./configure --prefix=/usr/local/libevent
    $ make && make install
    注:Mac下可能会出错:bufferevent_openssl.c:60:10: fatal error: 'openssl/bio.h' file not found,解决方案:

    brew install openssl

    brew link openssl --force

    cp -R /usr/local/Cellar/openssl/1.0.2h_1/include/openssl ~/software/libevent-2.0.22-stable 

     
    [安装memcached服务端]
    $ tar zxvf memcached-1.4.39.tar.gz
    $ ./configure --prefix=/usr/local/memcached --with-libevent=/usr/local/libevent
    $ make && make install
     
    [启动]
    $ cd /usr/local/memcached
    $ ./memcached -u root –d    #启动memcached
    $ ps -ef |grep memcached     #查看memcached运行状态
     
    【备注】设置memcached开机启动,vim打开/etc/rc.local在最后面写入:
    /usr/local/memcached/bin/memcached -u root -d
     
    [连接]
    $telnet 127.0.0.1 11211
    stats     --查看状态
    version       --查看版本
    set user 1 3000 10 --添加数据
    get user  --获取数据
    delete user    --删除数据
    flush_all --清空所有
     
    安装php-memcached扩展】
    [安装 libmemcached]
    $ tar zxvf libmemcached-1.0.18.tar.gz
    $ cd libmemcached-1.0.18/
    $ ./configure --prefix=/usr/local/libmemcached --with-memcached --enable-sasl
    $ make && make install
    注:Mac下可能会出错:error: use of undeclared identifier 'ntohll',解决方案:
    1)编辑libmemcached/byteorder.cc文件
    在 #include "libmemcached/byteorder.h" 下面增加以下内容:
    #ifdef HAVE_SYS_TYPES_H
    #include <sys/types.h>
    #endif
    
    (
    2)、编辑clients/memflush.cc文件 将两处 if (opt_servers == false) 替换成 if (opt_servers == NULL)
     
     
    [安装 php-memcached扩展]
    $ unzip php-memcached-php7.zip
    $ cd php-memcached-php7/
    $ /usr/local/php/bin/phpize
    $ ./configure --enable-memcached --with-php-config=/usr/local/php/bin/php-config --with-libmemcached-dir=/usr/local/libmemcached --enable-memcached-sasl
    $ make && make install

      安装完成后,在php.ini(/usr/local/php/php.ini) 后面添加 extension=memcached.so
     
     
     [PHP操作memcached]
    <?php
    $mem = new Memcached; //创建一个memcache对象
    $mem->addServer('127.0.0.1', 11211) or die ("Could not connect"); //连接Memcached服务器
    $mem->set('key', 'test'); //设置一个变量到内存中,名称是key 值是test
    $val = $mem->get('key'); //从内存中取出key的值
    echo $val;
    ?>
     
     
     
     
     
     
     
  • 相关阅读:
    05 库的简单操作
    04 基本的MySQL语句
    03 MySQL安装和基本管理
    02 数据库概述
    01 MySQL入门了解
    Django-组件拾遗
    bootstrap基础讲解
    jQuery练习
    前端基础之Jquery
    15 Django组件-中间件
  • 原文地址:https://www.cnblogs.com/rxbook/p/7137381.html
Copyright © 2011-2022 走看看