Little Ant learns memcache notes-php operation Memcache (1)

Source: Internet
Author: User
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 (' ', 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.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.