• memcache学习


    1.memcache和memcached区别

    Memcache是该系统的项目名称,Memcached是该系统的主程序文件(字母d可以理解为daemon),以守护程序方式运行于一个或多个服务器中,随时接受客户端的连接操作,使用共享内存存取数据。

    memcache客户端(php)

    PHP有两个memcache客户端:php memcache和php memcached。

    php memcache独立用php实现,是老客户端,从我们实践中已发现有多个问题,而且功能少,属性也可设置的少;

    2安装memcached

    yum search memcached

    有了,可以进行安装了

    memcache2

    yum -y install memcached

    memcache3

    memcache关联php
    yum -y install php-pecl-memcache

    memcache4

    验证安装结果
    memcached -h
    php -m | grep memcache

    参数说明:
    -d选项是启动一个守护进程;
    -m是分配给memcache使用的内存数量,单位是mB,我这里是100mB;
    -u是运行memcache的用户,我这里是root;
    -l是监听的服务器IP地址我这里指定了服务器的IP地址192.168.0.100;
    -p是设置memcache监听的端口,我这里设置了11211,最好是1024以上的端口;
    -c选项是最大运行的并发连接数,默认是1024,我这里设置了512,按照你服务器的负载量来设定;
    -P是设置保存memcache的pid文件,我这里是保存在 /tmp/memcached.pid;

    memcache的基本设置
    启动memcache的服务端:
    memcached -d -m 100 -u root -l 192.168.0.100 -p 11211 -c 512 -P /tmp/memcached.pid

    memcache5

    需要php扩展,就用下面这个命令
    pecl install memcache

    memcache6

    phpsize,运行yum install php-devel

    memcache7

    php.ini中的extension_dir = “./”修改为
    extension_dir = “/usr/local/php/lib/php/extensions/no-debug-non-zts-2007xxxx/”
    #注释掉:添加一行来载入memcache扩展:extension=memcache.so

    memcache8

    以上是探针显示。

    设置开机启动
    chkconfig memcached on

    启动和停止
    service memcached start | stop
    或者
    /etc/init.d/memcached start | stop

    Memcache环境测试:
    运行下面的php文件,如果有输出This is a test!,就表示环境搭建成功。开始领略Memcache的魅力把!
    < ?php
    $mem = new Memcache;
    $mem->connect(“127.0.0.1″, 11211);
    $mem->set(‘key’, ‘This is a test!’, 0, 60);
    $val = $mem->get(‘key’);
    echo $val;
    ?>

  • 相关阅读:
    use evolation+mapi with exhange mode
    python open file mode description
    5 reasons why you should learn python programming
    文本从尾到头输出
    安装部署lamp,来测试rediect
    python for ,loop ,else condition test
    python logging usage
    去除重复行
    [WTL]WTL for MFC Programming实践篇 一个自定义ComboBox的移植过程
    subsonic已死,db4o将死
  • 原文地址:https://www.cnblogs.com/sign-ptk/p/5655790.html
Copyright © 2020-2023  润新知