小飯包碎碎唸

21 Nov, 2007

在Windows 安裝 Memcache

Posted by: admin In: PHP

  1. 下載最新的 memcached-win32,解壓縮到 C:\memcached
  2. 開始→執行→輸入 ‘C:\memcached\memcached.exe -d install’
  3. 開始→執行→輸入 ‘C:\memcached\memcached.exe -d start’
  4. 修改php.ini,新增一行 ‘extension=php_memcache.dll’
  5. 下載 php_memcache.dll 至 C:\PHP\ext
  6. 重新啟動apache

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

然后就可以用php的memcached客户端来试一下了。
<?php
//test1.php
$memcache = new Memcache;
$memcache->connect(‘localhost’, 11211) or die (“Could not connect”);
$memcache->set(‘test’, ‘hello’);
?>

<?php
//test2.php
$memcache = new Memcache;
$memcache->connect(‘localhost’, 11211) or die (“Could not connect”);
echo $memcache->get(‘test’);
?>

blog comments powered by Disqus

誰來參觀

ChangPo Hu | 建立你的名片
ChangPo Hu

Google Friends


Technorati Profile