Memcache installation under Windows:
1. Download the memcache Windows stable version, extract and put under a certain disk, such as in c:memcached
2. In the terminal (also known as CMD Command Interface) under the input ' c:memcachedmemcached.exe-d install
' Installation
3. Re-enter: ' c:memcachedmemcached.exe-d start ' start. Note: Later
Memcached will automatically start as a service on Windows each time it is powered on. So that the server end is installed
Finished.
4. Download Http://cmy2009.ihost.tw/download, (Php_memcache address) please find the corresponding
PHP version of the file
5. Join a line of ' Extension=php_memcache.dll ' in C:winntphp.ini
6. Restart Apache, then check phpinfo, if there is memcache, then the installation is successful!
Basic Settings for memcached:
-P Listening Port
The IP address of the-l connection, the default is native
-D Start memcached service
-D Restart Restart memcached service
-D Stop|shutdown shut down the running memcached service
-D Install installation memcached service
-d Uninstall Uninstall memcached service
-U Run as (only valid when run as root)
-m maximum memory usage, in MB. Default 64MB
-M returns an error when memory is exhausted instead of deleting the item
-C Maximum Simultaneous connection number, default is 1024
-F Block size growth factor, default is 1.25
-N Minimum allocation space, key+value+flags default is 48
-H Display Help
Memcache Environment test:
Run the following PHP file, if there is output, it means that the environment has been built successfully. began to appreciate the charm of memcache
!
| The code is as follows |
Copy Code |
|
<?php
$memcache = Memcache_connect (' localhost ', 11211);
if ($memcache) {
$memcache->set ("Str_key", "string to store in memcached");
$memcache->set ("Num_key", 123);
$object = new Stdclass;
$object->attribute = ' Test ';
$memcache->set ("Obj_key", $object);
$array = Array (' Assoc ' =>123, 345, 567);
$memcache->set ("Arr_key", $array);
Var_dump ($memcache->get (' Str_key '));
Var_dump ($memcache->get (' Num_key '));
Var_dump ($memcache->get (' Obj_key '));
}
else {
echo "Connection to memcached failed";
}
?> |
Why not use a database to do this?
Do not consider what databases to use (Ms-sql, Oracle, Postgres, MySQL tutorials-innodb, etc ...), Implementing transactions (acid,atomicity, consistency, isolation, and Durability) requires a lot of overhead, especially when using a hard drive, which means that the query may block. When you use a database that does not contain a transaction, such as Mysql-myisam, the overhead does not exist, but the read thread may be blocked by the write thread. The
Memcached is never blocked, and is very fast.