How to install Memcached on Windows machine
After some research I found that there is a Win32 binary version of memcached available here.
So go there and download win32 binary version to your computer. When downloaded, extract the file to folder memcahced on your C partition.
You should get only one file named memcached.exe. Now we need to install this as a service, as memCached is daemon and should be run only as service.
To install Memcached as a service, follow these steps (please change all forward slashes to backslashes):
Change the ImagePath entry to:
This way you will use 512 Mb memory limit for your server.
If you are using WAMP, then just turn on php_memcache extension in it. Now we are ready to go testing.
The simplest test is to write something to memcache that will expire in 30 seconds, and then try to retrieve the value from cache.
So write this into your test file:
If everything went ok, you should see your array written out of memcache. Now you can use this powerful caching mechanism to develop really fast PHP applications. If you need to know more, go to PHP manual Memcached page
So go there and download win32 binary version to your computer. When downloaded, extract the file to folder memcahced on your C partition.
You should get only one file named memcached.exe. Now we need to install this as a service, as memCached is daemon and should be run only as service.
To install Memcached as a service, follow these steps (please change all forward slashes to backslashes):
- If you’re running Vista, you should set memcached.exe to Run as administrator
- Install the service using the command: from the command prompt
1c:/memcached/memcached.exe -d install - Start the server from the Services or by running one of the following commands: or
1c:/memcached/memcached.exe -d start
1net start "memcached Server"
1 | HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services/memcached Server . |
1 | “C:/memcached/memcached.exe” -d runservice -m 512 |
If you are using WAMP, then just turn on php_memcache extension in it. Now we are ready to go testing.
The simplest test is to write something to memcache that will expire in 30 seconds, and then try to retrieve the value from cache.
So write this into your test file:
01 | <?php |
02 | $memcache = new Memcache; // instantiating memcache extension class |
03 | $memcache->connect("localhost",11211); // try 127.0.0.1 instead of localhost |
04 | // if it is not working |
05 |
06 | echo "Server's version: " . $memcache->getVersion() . "<br />\n"; |
07 |
08 | // we will create an array which will be stored in cache serialized |
09 | $testArray = array('horse', 'cow', 'pig'); |
10 | $tmp = serialize($testArray); |
11 |
12 | $memcache->add("key", $tmp, 30); |
13 |
14 | echo "Data from the cache:<br />\n"; |
15 | print_r(unserialize($memcache->get("key"))); |
16 | ?> |
No comments: