zoukankan      html  css  js  c++  java
  • 如何在 Windows 下安装 Memcached

    (其实在Windows下安装还是比较简单的)

    源码包准备:

    1,memcached 1.2.1 for Win32 binaries

    这个是 Win32 服务器端的 memcached 最新版本,直接下载就可以了;

    2,php_memcache-5.2-Win32-vc6-x86-20090408.zip

    这个是 php 所需的 PECL 扩展,即 php_memcache 扩展;(一定要和自己的 PHP 版本相同,我用的是5.2.1)

    有了源码包包,那就开始大快朵颐吧,按照下面的步骤

    1. 将第一个包解压放某个盘下面,比如在c:\memcached
    2. 在终端(也即cmd命令界面)下输入 ‘c:\memcached\memcached.exe -d install’ 安装
    3. 再输入: ‘c:\memcached\memcached.exe -d start’ 启动。(需要注意的: 以后memcached将作为windows的一个服务每次开机时自动启动。这样服务器端已经安装完毕了)
    4. 解压第二个包包,里面会只有一个 php_memcache.dll 文件,把它放入 usr/local/php5/ext/ 中
    5. 在C:\WINDOWS\php.ini 加入一行 ‘extension=php_memcache.dll’(不知道为什么 PHP 会有两个配置文件,一个在 usr/local/php5/php.ini, 而另一个则在 C:/WINDOWS/中,而且只改前一个配置文件不起作用,所以就把 WINDOWS 中的 php.ini 也改掉了!)

    6,接着在 php.ini 文件里加上:

    [Memcache]
    memcache
    .allow_failover = 1
    memcache
    .max_failover_attempts=20
    memcache
    .chunk_size =8192
    memcache
    .default_port = 11211

    最好就放在刚才写 "extension=php_memcache.dll" 的下面。(这是默认的一些配置)
    6.重新启动Apache,然后查看一下phpinfo,如果有 memcache 的说明,那么就说明安装成功啦!

    试运行:

    写一个 example.php 文件:(更多使用方法可以参看 PHP 手册里的 Memcache Functions 使用说明)

    1
    2 <?php
    3
    4 $memcache = new Memcache;
    5 $memcache->connect('localhost', 11211) or die ("Could not connect");
    6
    7 $version = $memcache->getVersion();
    8 echo "Server's version: ".$version."<br/>\n";
    9
    10 $tmp_object = new stdClass;
    11 $tmp_object->str_attr = 'test';
    12 $tmp_object->int_attr = 123;
    13
    14 $memcache->set('key', $tmp_object, false, 10) or die ("Failed to save data at the server");
    15 echo "Store data in the cache (data will expire in 10 seconds)<br/>\n";
    16
    17 $get_result = $memcache->get('key');
    18 echo "Data from the cache:<br/>\n";
    19
    20 var_dump($get_result);
    21
    22 ?>

    如果有输出:

    Server's version: 1.4.5
    Store data in the cache (data will expire in 10 seconds)
    Data from the cache:
    object(stdClass)#3 (2) { ["str_attr"]=> string(4) "test" ["int_attr"]=> int(123) }

    则说明,我们的 Memcached 已经正常运行啦!  :~>



  • 相关阅读:
    Hibernate第一个程序(最基础的增删改查) --Hibernate
    基于Struts2框架的文件下载 --- Struts2
    Android+Servlet+MySql+JSON实现简单的数据查询操作--C/S架构
    Can't create handler inside thread that has not called Looper.prepare()
    HTTP Status 405
    Android+Struts2实现简单的前后台交互--Android网络编程
    NSOperation、NSOperationQueue(II)
    GCD(III)
    Runtime(IV)
    iOS第三方支付(支付宝)
  • 原文地址:https://www.cnblogs.com/catprayer/p/1719924.html
Copyright © 2011-2022 走看看