Windows下安裝Memcached的步驟說明

來源:互聯網
上載者:User

(其實在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 使用說明) 複製代碼 代碼如下:

<?php

$memcache = new Memcache;
$memcache->connect('localhost', 11211) or die ("Could not connect");

$version = $memcache->getVersion();
echo "Server's version: ".$version."<br/>\n";

$tmp_object = new stdClass;
$tmp_object->str_attr = 'test';
$tmp_object->int_attr = 123;

$memcache->set('key', $tmp_object, false, 10) or die ("Failed to save data at the server");
echo "Store data in the cache (data will expire in 10 seconds)<br/>\n";

$get_result = $memcache->get('key');
echo "Data from the cache:<br/>\n";

var_dump($get_result);

?>

如果有輸出: 複製代碼 代碼如下: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 已經正常運行啦! :~>

如果上面的地址不能下載,可以到http://www.splinedancer.com/memcached-win32/下載

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.