Coder Profile - Show off your skills, get a coder profile.
 
 
 
How to use Memcache on Windows
Web Development
I will quickly run you through an example of HOW to use memcache and how it works.

Download Memcache

http://jehiah.cz/projects/memcached-win32/

And load up the .exe - you should just get a blank command box appear - the server is then running on localhost:11211

Install the Memcache extensions in to PHP

If you use something like xamp or easyphp - just enable the memcache exentions (just a case of maybe uncommenting a line or ticking a box like in easyphp).

Code Example
CODE: Copy / Restore  ::  Remove Scroll Bars
  1. $memcache = new Memcache();
  2. $memcache->connect('localhost', 11211);
  3. $memcache->add('name', 'Scott Thompson', false, 60);
Put that code in a .php page (remember to have the memcache server running). Now simply run the script and it will save my name in memory for 60 seconds! To retrieve the value from memory now put this in the script (within 60 seconds else it will expire from memory).
CODE: Copy / Restore  ::  Remove Scroll Bars
  1. $memcache = new Memcache();
  2. $memcache->connect('localhost', 11211);
  3. print $memcache->get('name');
And you will see that my name is still there!

It's quite simple really. You use add() to add new values to memory where they are stored... and you use get() to retrieve a value from memory. Remember that the values are kept in memory even after the .php script finishes executing and the memory is SHARED between other .php scripts.

Kind regards,
Scott
Please login to rate coding articles.

Click here to register a free account with us.
Comments
Please login to post comments.
 
Craige     Posted 2.82 Years Ago
 
 
Awesome. I'll have to do some benchmarking.
 
VBAssassin     Posted 2.82 Years Ago
 
 
Forever.. i.e. until you restart the computer.
 
Craige     Posted 2.82 Years Ago
 
 
What is the maximum time you can store a variable in memory?
Page 1 of 1
More Articles By This Author
[PHP] - Lets kill the complex IF
How to use Memcache on Windows
PHP Sessions = Member Database Cache
Speed Up Delivery of your JavaScript Libraries
AJAX - When to use it?
Null Byte Poison - How it works...
Versioning Your Application
Preventing raw PHP leaks on Apache
All VB6 Global Functions & Objects
ASCII List
Scott Thompson (24)
United Kingdom, Lincolnshire
VBAssassin has 32 fans
become a fan
� Applications
Articles Articles (13)
Source Codes Source Codes (61)
� About Me
About Me About Me
User Groups User Groups (9)
Portfolio Portfolio (8)
Friends Friends (178)
� Misc
Overview Overview
Send A Friend Invite
Send Message Send A Message
RSS Whole Profile Feed
 
 
Latest News About Coder Profile
Coder Profile Poll
If you made money from keeping your profile up to date, say $30 and up, per month. What extra time would you spend on your profile?

No extra time
A few hours at weekends
A whole day each week
Every minute i can get free


please login to cast your vote
and see the results of this poll
Latest Coder Profile Changes
Coder Profile was last updated
2.96 Years Ago
Official Blog :: Make A Donation :: Credits :: Contact Me
Terms & Conditions :: Privacy Policy :: Documents :: Wallpapers
Version 1.46.00
Copyright � 2007 - 2011, Scott Thompson, All Rights Reserved