Windows下的Memcache安裝與測試教程

來源:互聯網
上載者:User

Windows下的Memcache安裝
1、下載memcache for windows。下載地址:http://jehiah.cz/projects/memcached-win32,推薦下載binaries版本,解壓(本例中解壓到c:memcached)。
2、在命令列狀態下輸入: c:memcachedmemcached.exe -d install 。至此memcached已經安裝成windows服務
3、在命令列下輸入: c:memcachedmemcached.exe -d start 以啟動memcached服務。當然也可以選擇在windows服務中啟動
你沒看錯,就是這麼簡單,簡簡單單的三步memcache的伺服器端就準備完畢

php安裝Memcached模組支援
1、下載php_memcache.dll模組,你可以從http://downloads.php.net/pierre/找到對應的版本,
php5.3的直接下載http://shikii.net/blog/downloads/php_memcache-cvs-20090703-5.3-VC6-x86.zip

2、修改php.ini,添加如下內容:

extension=php_memcache.dll3、重啟apache伺服器,然後查看一下phpinfo,如果有memcache,那麼就說明安裝成功!

測試windows下的Memcached
測試代碼如下:

 代碼如下 複製代碼

<?php
$mem = new Memcache;
$mem->connect("127.0.0.1", 11211);
$mem->set('key', 'Hello Memcached!', 0, 60);
$val = $mem->get('key');
echo $val;
?>

Example #1 memcache extension overview example

In this example, an object is being saved in the cache and then retrieved back. Object and other non-scalar types are serialized before saving, so it's impossible to store resources (i.e. connection identifiers and others) in the cache.

 代碼如下 複製代碼

<?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);

?>


Example #2 Using memcache session handler

 代碼如下 複製代碼

<?php

$session_save_path = "tcp://$host:$port?persistent=1&weight=2&timeout=2&retry_interval=10,  ,tcp://$host:$port  ";
ini_set('session.save_handler', 'memcache');
ini_set('session.save_path', $session_save_path);

?>


-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 顯示協助

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.