Cài đặt Memcache cho xampp 3.2.1 với php 5.6.x trên window 7

1. Tải xampp 3.2.1 tại địa chỉ http://www.apachefriends.org/en/xampp-windows.html và cài đặt bình thường.
2. Tải memcache server tại địa chỉ : https://commaster.net/content/installing-memcached-windows
– Download bản memcache phù hợp
32bit : http://downloads.northscale.com/memcached-win32-1.4.4-14.zip
64bit : http://downloads.northscale.com/memcached-win64-1.4.4-14.zip

Sau khi download xong giải nén được file memcached.exe và copy nó vào thư mục bất kỳ.
Ví dụ (d:/Programs/Memcache/win64-1.4.4-14/memcached.exe)

Mở chương trình cmd của window
– Di chuyển đến ổ D
cd d:
– Di chuyển đến thư mục chứa file memcache.exe
cd Programs\Memcache\
– Cài đặt memcache bằng lệnh
d:\Programs\Memcache\win64-1.4.4-14\memcached.exe -d install
– Khởi động memcache
d:\Programs\Memcache\win64-1.4.4-14\memcached.exe -d start
– Dừng memcache
d:\Programs\Memcache\win64-1.4.4-14\memcached.exe -d stop
3. Tải extention cho xampp tại địa chỉ http://windows.php.net/downloads/pecl/releases/memcache/3.0.8/ lựa chọn phiên bản 5.6 phù hợp với phiên bản xampp của bạn 32bit là x86, 64bit là x64
– php_memcache-3.0.8-5.6-ts-vc11-x86 (bản 32bit)

Sau khi download xong giải nén được file php_memcache.dll và copy nó vào thư mục “ext” trong đường dẫn cài đặt xampp. ví dụ (c:/xampp/php/ext/)

4. Vào xampp control click nút Config (Module Apache) chọn mở file php.ini rồi thêm vào dòng sau :

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

2016-09-19_141515

5. Khởi động lại memcache bằng cách dùng các lệnh trên trong cmd

2016-09-19_1417576. Khởi động lại xampp

7. Kiểm tra thử memcache đã hoạt động hay chưa bằng cách viết 1 đoạn code php
<?php
$memcache = new Memcache;
$memcache->connect(‘localhost’,11211); # You might need to set ‘localhost’ to ’127.0.0.1′
echo ‘Server\’s version: ‘ . $memcache->getVersion() . ‘<br /><hr />’;
if (!$memcache->get(‘key’))
{
$tmp_object = new stdClass;
$tmp_object->author = ‘Phạm Thanh Hiền’;
$tmp_object->email = ‘hienpthanh@gmail.com’;
$tmp_object->website = ‘https://hienpthanh.blogspot.com’;
$tmp_object->date = date(‘d-m-Y h:i:s’, time());
$memcache->set(‘key’,$tmp_object,false,30);
echo ‘<b>Store data in the cache (data will expire in 30 seconds)</b><br />’;
}
else
{
echo ‘<b>Read data from cache you have created</b> <br />’;
}
echo ‘<hr />Data from the cache:<br />’;
echo ‘<pre>’;
var_dump($memcache->get(‘key’));
echo ‘</pre>’;
echo ‘<hr />Current date time:’ .date(‘d-m-Y h:i:s’, time());
?>

(^_^)