Using Memcache in PHP projects

Source: Internet
Author: User

Memcache is a distributed memory cache system that reduces the load on the database by accessing data and objects in memory, and memcache into the client and server, the server as the C implementation, the ready-made service-side application, the need to configure the server-side listening address and port. , this document records PHP implementation Memcache client

The client to use Memcache cache data, to have two conditions, the first PHP memcache extension to open, you can wamp php->php extension, check Php_memcache, You can also directly modify the php.ini file, will extension=php_memcache.dll before, remove, restart the service, the second condition is that there must be a memcache server

After extracting the Memcache Server installation package to the C:\memcached folder, use the CMD command window to install it.

1> Start > Run: CMD (OK)

2>CD C:\memcached (carriage return)

3>memcached-d Install (enter this step to perform the installation)

4>memcached-d Start (Enter this step to start the Memcache server, default allocation of 64M memory, using 11211 port)

Now that the Memcache server is ready to use, you can use Telnet to access the cache

$ telnet localhost 11211Trying 127.0.0.1Connected to Localhost.localdomain (127.0.0.1). Escape character is ' ^] '. Set foo 0 0 3 (Save command) bar (data) STORED (result) get foo (get command) VALUE Foo 0 3 (data) bar (data)

Memcache Client connection and access is implemented using the original PHP Memcache class, as shown in the code below:

$cache = new Memcache ();

Connecting to the service side

$cache->connect (' localhost ', 11211);

Write cache, last parameter indicates cache expiration time, 0 means never expire, can use flush to clear cache

$cache->set (' aaaaa ', ' wqerqwerqwerqwerwqer ', ', 0);

Read cache

$cache->get (' aaaaa ');

Reference: http://php.net/manual/zh/book.memcache.php

Using Memcache in PHP projects

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: info-contact@alibabacloud.com 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.