The use of memcache, memcache use_PHP tutorial
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'); ?>
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')
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
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.
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

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

In web development, we often need to use caching technology to improve website performance and response speed. Memcache is a popular caching technology that can cache any data type and supports high concurrency and high availability. This article will introduce how to use Memcache in PHP development and provide specific code examples. 1. Install Memcache To use Memcache, we first need to install the Memcache extension on the server. In CentOS operating system, you can use the following command

In PHP development, using the Memcache caching system can greatly improve the efficiency of data reading and writing. Memcache is a memory-based caching system that can cache data in memory to avoid frequent reading and writing of the database. This article will introduce how to use Memcache in PHP for efficient data reading and writing operations, and provide specific code examples. 1. Install and configure Memcache First, you need to install the Memcache extension on the server. able to pass

How to use Memcache for efficient data writing and querying in PHP development? With the continuous development of Internet applications, the requirements for system performance are getting higher and higher. In PHP development, in order to improve system performance and response speed, we often use various caching technologies. One of the commonly used caching technologies is Memcache. Memcache is a high-performance distributed memory object caching system that can be used to cache database query results, page fragments, session data, etc. By storing data in memory

The practice and thinking of Memcache caching technology to optimize data interaction in PHP In modern Web applications, data interaction is a very important issue. It is not efficient enough and will limit the scalability and performance of Web applications. In order to speed up data interaction, our usual approach is to optimize the design of the database, improve the performance of the hardware and increase the server capacity. However, these methods all have a common limitation: they increase the cost of the system. In recent years, Memcache technology has made progress in solving this problem.

With the rapid development of the Internet, more and more applications need to face a large number of concurrent requests. How to improve the concurrent processing capabilities of applications has become a problem that developers need to solve. Among them, using Memcache caching technology for concurrency optimization has become a relatively popular solution. Memcache is an efficient caching technology suitable for large-scale web applications, databases and distributed systems. Its characteristic is to store data in memory to achieve high-speed read and write operations. During the data access process of web applications,

Memcache is an open source, distributed caching technology. It greatly improves the speed of data access by storing data in memory, thus improving the performance and responsiveness of the website. In PHP projects, Memcache caching technology is also widely used and has achieved good results. This article will deeply explore the application and practice of Memcache caching technology in PHP projects. 1. Principles and advantages of Memcache Memcache is a memory caching technology that can store data

As web applications become increasingly complex, performance has become a critical issue. In many applications, database queries are one of the most time-consuming operations. In order to avoid frequently reading data from the database, a caching system can be used to store frequently read data in memory for quick access. In PHP development, using Memcached for distributed caching is an extremely common practice. In this article we will introduce how to use Memcached for distributed caching. What is Memca

How to use Memcache to optimize data storage operations in your PHP application? In web application development, data storage is a crucial link. In PHP applications, Memcache, as a memory cache system, can effectively improve the efficiency of data storage and reading operations. This article will introduce how to use Memcache to optimize data storage operations in PHP applications, and attach specific code examples. Step 1: Install the Memcache extension First, you need to install Me in your PHP environment
