您的位置:首页 > 数据库 > Memcache

wamp安装memcached php方法win32

2015-08-20 10:10 756 查看
1. 下载 memcached-win32-1.4.4-14.zip (我的百度网盘有下载或者这个地址http://download.csdn.net/download/xujishou/3538984),里面包含6个文件,将解压后的文件夹随便放在什么位置。如果需要win64版,下载 memcached-win64-1.4.4-14.zip ,里面有个三个文件,用这三个文件覆盖win32下同名文件。

2. 以管理员身份运行 cmd.exe,并转至memcached所在文件夹,比如: cd c:\memcached 。(如果不以管理员身份运行,将得到报错“failed to install service or service already installed”)

3. 安装memcached:  

  c:\memcached> memcached.exe -d install

  (之后屏幕无任何提示)

4. 启动memcached:

  c:\memcached> memcached.exe -d start

  (之后屏幕无任何提示,但是在“任务管理器”中勾选“显示所有用户进程”,此时可以看到memcached.exe进程正在运行)

  默认端口11211,外部访问需要开放该端口,否则无法成功连接。

5. memcached基本参数设置:

    -p 监听的端口
    -l 连接的IP地址, 默认是本机
    -d start 启动memcached服务
    -d restart 重起memcached服务
    -d stop|shutdown 关闭正在运行的memcached服务
    -d install 安装memcached服务
    -d uninstall 卸载memcached服务
    -u 以的身份运行 (仅在以root运行的时候有效)
    -m 最大内存使用,单位MB。默认64MB
    -M 内存耗尽时返回错误,而不是删除项
    -c 最大同时连接数,默认是1024
    -f 块大小增长因子,默认是1.25
    -n 最小分配空间,key+value+flags默认是48
    -h 显示帮助

  设置参数时需要先停止memcached,然后用命令行设置,比如:c:\memcached> memcached.exe -m 1 -d start

6. 停止memcached:

  c:\memcached> memcached.exe -d stop

7. 卸载memcached:

  c:\memcached> memcached.exe -d uninstall

 

相关问题:

1. 设置最大占用内存后好像没起作用。

  -m tells memcached how much RAM to use for item storage (in megabytes). Note carefully that this isn't a global memory limit, so memcached will use a few % more memory than you tell it to. Set this to safe values. Setting it to less than 48 megabytes
does not work properly in 1.4.x and earlier. It will still use the memory.

  转自:http://stackoverflow.com/questions/6112324/memcached-using-more-than-max-memory

  参考:https://code.google.com/p/memcached/wiki/NewConfiguringServer

2. 在同一个程序集里将一个值放入到memcache里,马上去时可以取到,但是在另一个程序集里取的时候取不到,或者telnet也拿不到值。

 可能问题及解决办法:

    a. 存储的值序列化后不同类型,则需要将其更新为同一类型,建议使用同一的常见类型,如string,int等,放入string可以拼成一个xml字符串,然后到使用的时候在做解析

    b. 很有可能是memcache池已经满了,可以设置<socketPool minPoolSize="100" maxPoolSize="1000" connectionTimeout="00:10:00" deadTimeout="00:02:00"/>

最近想对自己做的系统性能优化。主要是想实现浏览器端的缓存和服务器端的缓存。与HTTP与HTTPd类似,

一直没有找到合适的教程,我研究了半天得出了这些东西

memcache与memcached这两个一个属于客户端,另一个属于服务器端驻留程序。

PHP中配置 Memcache

1、下载: http://download.csdn.net/detail/zhonggewei/3287497 有完整的包,还提供pthreadGC2.dll扩展。
2、php扩展-》添加扩展会有一个CMD出现,c:memcached/pthreadGC2.dll-d  - install  安装
 默认在php\ext\

3、在PHP.ini 加入一句话:extension=php_memcache.dll

4、重启WEB服务,使用 phpinfo() 函数查看启用情况(会有一项显示memcached)

2:PHP中测试 Memcache功能

$mem = new Memcache;

$mem->connect('127.0.0.1', 11211) or die("连接失败");

$mem->getVersion();

竟然出现连接失败(报错)

上述问题出现的解决方案:是因为没有安装memcached服务器进程程序

3:、的安装和PHP中的配置

1、解压到目录:c:\mem (自定义,任何目录)

2、c:\mem\memcached.exe -d install

3、c:\mem\memcached.exe -d start (启动服务)

测试用例:

<?php

 $test=new Memcache ;

 $test->connect('127.0.0.1',11211)or die("failure");

 $s=$test->getVersion();//不要单纯的只是$test->getVersion(),如果想在浏览器端显示的话,还是需要保存后输出的

 echo “memcache's version is:”$s ;

我测试成功代码:

<?php
$mem = new Memcache;
//$mem->connect("10.40.24.66", 11211);
$mem->connect("127.0.0.1", 11211);
//保存数据
$mem->set('key1', 'This is first value', 0, 60);
$val = $mem->get('key1');
echo "Get key1 value: " . $val ."";

exit;

输出:Get key1 value: This is first value
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: