PHP MemCached advanced cache configuration graphic tutorial

  • 2020-03-31 21:00:46
  • OfStack

1. Related introduction of Memcache

Memcache is a high-performance distributed memory object caching system that can be used to store data in a variety of formats, including images, videos, files, and database retrieval results.
In order to relieve the pressure of database, Memcache should be used as a cache area to save part of the information in memory. In the front end, it can be accessed quickly.

2. Installation of Memcache Win32
(1) download address:
http://www.jehiah.cz/projects/memcached-win32/
(2) installation steps:
Step1 extract the compressed package to any directory, such as c:\mem. The directory structure is as follows:
< img border = 0 SRC = "http://files.jb51.net/upload/201008/20100805165119343.jpg" border = 0 >
Step2 install memcache into the Windows service :c:\mem\memcached. exe-d install.
Step3 start memcache service :c:\mem\memcached. exe-d start. As shown in the following figure:
< img border = 0 SRC = "http://files.jb51.net/upload/201008/20100805165204649.jpg" border = 0 >
Note: step2 and step3 are not required if you do not need to add memcache to the Windows service, but instead start memcached.exe in the root directory each time you manually double-click to unzip it. Step2 and step3 above require action at a command prompt.

(3) test whether the installation is successful
After the memcache service starts successfully, you can use Telnet 127.0.0.1 11211 to test the connection. If the connection is successful, you can use the stats command to see the basic information of memcache. The details are shown in the following figure:
The < img border = 0 style = "DISPLAY: block; MARGIN - LEFT: auto; MARGIN - RIGHT: auto "SRC =" http://files.jb51.net/upload/201008/20100805165339307.jpg ">  

The < img border = 0 style = "DISPLAY: block; MARGIN - LEFT: auto; MARGIN - RIGHT: auto "SRC =" http://files.jb51.net/upload/201008/20100805165339457.jpg ">

The < img border = 0 style = "DISPLAY: block; MARGIN - LEFT: auto; MARGIN - RIGHT: auto "SRC =" http://files.jb51.net/upload/201008/20100805165339486.jpg ">

3.Memcache configuration in PHP

      (1) configuration steps

              Step1 download the php_memcache.dll component and place it in the PHP extension component directory, e.g. PHP \ext\
                Step2 after php.ini adds extension=php_memcache.dll, restart Apache.

      (2) test whether the configuration is successful

              Use phpinfo() to see if it was enabled successfully. As shown in the following figure:

      The < img border = 0 style = "DISPLAY: block; MARGIN - LEFT: auto; MARGIN - RIGHT: auto "SRC =" http://files.jb51.net/upload/201008/20100805165339785.jpg ">

      (3) test memcache in PHP

 
<?php 
$mem = new Memcache; 
$mem->connect('127.0.0.1',11211) or die(" The connection fails "); 
$mem->getVersion(); 
?> 


Related articles: