The use of memcache, memcache use_PHP tutorial

WBOY
Release: 2016-07-13 10:17:21
Original
903 people have browsed it

Use of memcache, use of memcache

What is memcache?

Memcache is a high-performance distributed memory object caching system. By maintaining a unified huge hash table in the memory, it can be used to store data in various formats, including images, videos, files and database retrieval. The results etc. Simply put, it is to call the data into the memory and then read it from the memory, thus greatly improving the reading speed (from 360 Encyclopedia)

It is equivalent to an in-memory database, which can reduce operations on the database.

I first saw it in a PHP interface server of the company.

Installation:

Installation method in ubuntu: Digging (fill in next time, I forgot the steps)

apt-get install memcached

After installation

sudo memcached start start

/etc/memcached.conf is the default configuration file

-p Listening port
-l Connected IP address, the default is the local machine
-d start Start memcached service
-d restart Restart memcached service
-d stop|shutdown Close Running memcached service
-d install Install memcached service
-d uninstall Uninstall memcached service
-u Run as (only valid when running as root)
-m Maximum memory usage , unit MB. Default 64MB
-M Return error when memory is exhausted instead of deleting items
-c Maximum number of simultaneous connections, the default is 1024
-f Block size growth factor, the default is 1.25-n Minimum allocated space, The default value of key+value+flags is 48
-h Show help 2) Install Memcache client

php memcache module installation method:

sudo apt-get install php5-memcache

Instructions for use: The php manual contains instructions for using this module

<?php
/* OO API */

$memcache_obj = new Memcache;

/* connect to memcached server */
$memcache_obj->connect('memcache_host', 11211);

/*
设置'var_key'对应值,使用即时压缩
失效时间为50秒
*/
$memcache_obj->set('var_key', 'some really big variable', MEMCACHE_COMPRESSED, 50);

echo $memcache_obj->get('var_key');
?> 
Copy after login

Python: Module download address https://pypi.python.org/pypi/python-memcached

 import memcache

 mc = memcache.Client(['127.0.0.1:11211'])
 mc.set('hello','world')
 mc.get('hello')
Copy after login

Some notes:

Memcached does not have security certification, so if the configured -l listening IP is set to an IP other than the local one, it may cause data security issues

Fill in the pits later when you are familiar with it

How to use and configure CI’s memcache

CI is memcacehd. What you installed is memcache. There is a "d" character missing, and the difference is huge. CI only supports memcached, not memcache. There is only memcache under Windows.

How to use memcache cache reasonably? How to deploy if the amount of cached data is too large?

The memcache server requires special configuration, large memory, and other hardware can be used
Other solutions: you can configure distributed cache
because memcache is generally only used by the local area network
The working principle is: web server Use memcache to cache, and then cache the data on the memcache server. Memecache only uses memory

If the amount of data is too large, you can only add a server. If you deploy a distributed cache

for others, please contact us

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/893203.htmlTechArticleUsage of memcache, what is memcache used? Memcache is a high-performance distributed memory object caching system. By maintaining a unified huge hash table in memory, it...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!