Preparatory work
Copy the Php_memcache.dll file to PHP ext.
Special Note: Different versions of PHP use different versions of Php_memcache.dll.
Modify the php.ini file to load the Php_memcache.dll (this file is actually loaded with a whole bunch of functions)
Restart Apache
PHP actual operation
$mem = new Memcache (); Instantiating an Object
$mem = Connect (' 127.0.0.1 ', 11211);
$mem, add (key, value, whether compressed, time to live);
$mem, set (IBID.); The key is modified if it exists and does not exist to add
Memcache can save strings and arrays, numbers, objects
When you save an object, there is a problem: there is one thing to be aware of when you remove an object from another file. Corresponding php5.2 This version will prompt the error, php5.3 This version will prompt incomplete information. This error is the same as saving it in $_session, and the solution is the same.
WORKAROUND: Re-declare the class definition in the current script (take the class too)
Add NULL to remove null
Add false to remove '
Modify $mem->replace (same as add);
Delete $mem->delete (key);
Flush all out.
Attention to detail: When adding data, if expire (timeout) is set to 0, it means that it never expires. Expire directly to the number of seconds, the maximum can only be 30 days, that is, 30*3600*24. If you want to keep time longer than 30 days, use a timestamp, that is, time () + days *3600*24.
Put resources, but 0, so the resources are not supported. Note
When you add an array, you can serialize Serializa () as needed to save the objects and arrays on disk.
There are also JSON, which can also be converted into strings. The difference is that Serializa () can save some information about the type and size of the data, mainly for storing data. Json_encode () does not save information such as data type, mainly to facilitate the transmission of data.