Install and use phpmemcached

Source: Internet
Author: User
1. introduction The memcache module is an efficient daemon process that provides process programs and object-oriented interfaces for memory cache, especially when designing dynamic web programs to reduce access to the database. memcache also provides communication dialogs (ses... 1. Introduction

The memcache module is an efficient daemon that provides process programs and object-oriented interfaces for memory caching, especially for designing dynamic web programs to reduce access to databases. memcache also provides processing for communication conversations (session_handler.

1.1.memcache configuration item list in php. ini

Variable change log by default name

memcache.allow_failover  "1"  php_ini_all  available since memcache 2.0.2.  memcache.max_failover_attempts  "20"  php_ini_all  available since memcache 2.1.0.  memcache.chunk_size  "8192"  php_ini_all  available since memcache 2.0.2.  memcache.default_port  "11211"  php_ini_all  available since memcache 2.0.2.  memcache.hash_strategy  "standard"  php_ini_all  available since memcache 2.2.0.  memcache.hash_function  "crc32"  php_ini_all  available since memcache 2.2.0.  session.save_handler  "files"  php_ini_all  supported since memcache 2.1.2  session.save_path  ""  php_ini_all  supported since memcache 2.1.2

For more information and definitions of php_ini _ * constants, see The php Manual. ini configuration options. the following code is used to give you an intuitive impression: (assume that memcached is installed on 172.10.10.10, and the port number is 12121 ):

$ Memcache = new memcached (); $ memcahce-> connect ('2017. 10.10.10', 12121); $ memcache-> set ('key', 'value'); // open-source code phprm.com $ memcache-> get ('key ');

The above describes the simple operation process of memcached: connect to the memcached server, set the value, and set the value (the value of 'key' is 'value ');

Here we need to explain the addserver function and connect function. addserver puts multiple servers in the connection pool, while connect only connects to a server. if addserver is used, connect is used, here, only one server is used. the following code is a simulated client operation:

$ Fp = fsocketopen ('1970. 10.10.10 ', 172, $ errorno, $ errstr, 1); if (! $ Fp) echo "$ errstr"; else {$ out = "get key rn"; fwrite ($ out); while (! Feof ($ fp) $ str. = fgets ($ fp); if (stripos ($ str, 'end') = 0) // open source code phprm.com exit ("no value find ") $ arr = implode ('RN ', $ str); echo $ arr [1];}

Briefly explain the above code, use fsocketopen to open the socket communication interface of the server, then send the get key command to it, then obtain the returned data, and parse the returned data. No exception is processed here, memcached is a key-value storage system that stores key data in the memory, greatly reducing the time for data access. the advantages of using memcached are self-evident, it not only reduces the pressure on the system to access the database, but also increases the response speed of the system. As for what system needs to use memcache, I suggest a large amount of data, frequently accessed systems can use memcached as the cache middle layer.

The disadvantage of using memcached is not only to increase the amount of code in the program, but also to ensure the real-time performance of the database. In addition, it takes additional time to initialize the database for the first time, however, these shortcomings are insignificant compared to their advantages.


Permanent address:

Reprint at will ~ Please bring the tutorial URL ^

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.