The php memory cache technology has heard the memcached name in many occasions, but I have only heard of it and I have never used it or actually understood it. I only know it is a good stuff. Memcached is an efficient and fast distributed memory object cache system, mainly used to accelerate dynamic WEB applications. Recently I learned about memcached, first of all, the php memory cache technology.
I have heard of the memcached name in many occasions, but I have only heard of it, but I have never used it or actually learned it. I only know it is a good stuff. Memcached is an efficient and fast distributed memory object cache system, mainly used to accelerate dynamic WEB applications. I recently learned about memcached.
The first step is to download memcached, which is available in both windows and linux versions. it is very easy to run the memcached daemon. you only need one command line and do not need to modify any configuration files:
/Usr/bin/memcached-d-m 128-l 192.168.1.1-p 11211-u httpd
Parameter description:
-D run memcached in daemon mode;
-M: Set the memory size that can be used by the PHP memory cache technology memcached. the unit is M;
-L set the IP address of the listener. if it is a local machine, this parameter is usually not set;
-P: Set the listening port. the default value is 11211. Therefore, you can leave this parameter unspecified;
-U indicates the user.
Connect ('localhost', 11211) or die ("cocould not connect"); // connect to memcache $ version = $ memcache-> getVersion (); // Obtain the memcache version echo "Server's version :". $ version."
"; $ Tmp_object = 123; if ($ memcache-> get ('key') {$ memcache-> increment ('key', 2 ); $ va = $ memcache-> get ('key'); echo $ va; // variable auto-increment, the variable is stored in the memory, after modification, refresh and keep modification var_dump ($ memcache-> getStats (); exit () ;}$ memcache-> add ('key', $ tmp_object, false, 10) or die ("Failed to save data at the server"); echo "Store data in the cache (data will expire in 10 seconds)
"; $ Get_result = $ memcache-> get ('key'); echo" Data from the cache:
"; Var_dump ($ get_result); var_dump ($ memcache-> getStats ();?>
?
?