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
|
$memcache = new Memcache(); $memcache->connect('localhost', 11211); $memcache->add('name', 'Scott Thompson', false, 60);
Select what you want to copy and in doing so you will keep the formatting when pasting it.
|
|
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
|
$memcache = new Memcache(); $memcache->connect('localhost', 11211); print $memcache->get('name');
Select what you want to copy and in doing so you will keep the formatting when pasting it.
|
|
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,
ScottPlease login to rate coding articles.
Click here to register a free account with us. |
|
Comments
|
Please login to post comments. |
|
Awesome. I'll have to do some benchmarking.
|
|
Forever.. i.e. until you restart the computer.
|
|
What is the maximum time you can store a variable in memory?
|
|
|
 |
Scott Thompson (24) United Kingdom, Lincolnshire |
|
VBAssassin has 32 fans
become a fan |
|
 |
|
 |
|