Recently I was asked to get memcached working with PHP 5.4.8 on my Windows 7 64 bit machine at work, took a while and some looking around, but I was able to get it working successfully. Below are the steps which I took to get it to work. Hopefully this helps someone else in the future.
Assumptions:
- You have apache, php 5.4 installed. my directories are as follows:
c:\etc\php
c:\etc\apache - You are an admin on your machine... If you aren't get access.
- I'm using Windows 7, 64 bit
- In reading this you realize that this is what has worked for ME, I can't promise that it will work for you, nor do I take any responsibility for any of the files below. They didn't break my machine, but who knows what they will do to yours. Use at your own risk
Let's get down to business!
- Download this http://code.jellycan.com/files/memcached-1.2.6-win32-bin.zip
- Unzip here: c:/etc/memcahced
- Right click ->; properties ->; compatibility ->; run as admin
- Go to command line:
c:\etc\memcached\memcached.exe –d install - If window throws an error saying that it is missing or can not find "MSVCR71.dll" do the following, else go to #6
- Download this: http://www.box.net/shared/jn252o074v
- Copy file to c:\windows\system32
- Try #4, if it works, great go to #6,
- Didn’t work huh? Ok, move file to c:\windows\system and try again.
- Still didn't work? I've heard going placing in C:\windows\sysWOW64 works... but I haven't tried that.
- Go to services.msc, start service (find where it says memcached, right click and hit 'start')
- Confirm everything is proper by going to regedit and making sure you have this:
HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services/memcached
to access regedit open a run window and type 'regedit' - Raise memory limit (if you want):
c:\etc\memcached\memcached.exe –d runservice –m 512 - Download PHP .dll (now as I've said earlier, this is only for php 5.4): http://windows.php.net/downloads/pecl/releases/memcache/3.0.6/php_memcache-3.0.6-5.4-ts-vc9-x86.zip
- Unzip contents to c:\etc\php\ext
- Add the following to php.ini
extension=php_memcache.dll - Restart server
- Add this to a test page:
//Create a new instance of memCached
$memcache = new Memcache;
//Of course you can use "localhost" instead of the IP if you want
$memcache->connect('127.0.0.1', 11211) or die ("Could not connect");
//Get the version, cause why not
$version = $memcache->getVersion();
echo "Memcache's version: $version
\n";
\n";
//Make some object
$tmp_object = (object) null;
$tmp_object->;someString = 'Testing...';
$tmp_object->;someInt = 9083202;
//Get the contents of the memcache
$get_result = $memcache->;get('key');
echo "-- Data currently in the cache:
\n";
\n";
var_dump($get_result);
//set the memcache
$memcache->set('key', $tmp_object, false, 15) or die ("Failed to save data at the server");
echo "
\n-- Data is stored in the cache, will expire in 15 seconds
\n";
\n-- Data is stored in the cache, will expire in 15 seconds
\n";
//Get the contents of the memcache
$get_result = $memcache->;get('key');
echo "-- Data currently in the cache:
\n";
\n";
var_dump($get_result) ;
5 comments:
Nice one dude! Works for me! Thanks.
Please note that this is Memcache and not Memcached. Has someone been able to setup the php extension for Memcached?
Your idea is working for memcache only not for memcached.Please mention it in your post title
Thank you, it's great.
But link http://windows.php.net/downloads/pecl/releases/memcache/3.0.6/php_memcache-3.0.6-5.4-ts-vc9-x86.zip
Now it need change: http://windows.php.net/downloads/pecl/releases/memcache/3.0.8/php_memcache-3.0.8-5.3-ts-vc9-x86.zip
Tks
Post a Comment