Home  >  Article  >  Backend Development  >  PHP and memcache installation and usage instructions_PHP tutorial

PHP and memcache installation and usage instructions_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:36:45854browse

After the recent increase in website traffic, the number of database connections has been high. After analysis, it is found that they are all normal requests. However, the website functions are divided into details. There are too many single-page database query sentences. A lot of data is unnecessary. Real-time query, just cache it! Consider using memcache for caching to reduce the pressure on mysql!

Project name: 15-day weather forecast query website http://15tianqi.cn

Cause of the problem: There are too many mysql connection requests and the database is under great pressure

Solution: Install and enable memcache

What is Memcache? Memcache is a free and open source, high-performance, allocated memory object caching system. Used to accelerate dynamic web applications and reduce database load.

It can handle any number of connections and uses non-blocking network IO. Since its working mechanism is to open up a space in the memory and then create a HashTable, Memcached manages these HashTables by itself. Memcached is simple yet powerful. Its simple design promotes rapid deployment, eases development problems, and solves many of the problems faced by large data caches. Its API is available for the most popular languages.

No matter what, if we want to use memcache as a memory cache, we must install memcache into php and then install memecached in the linux system. In this way, PHP can access data in memory through memecache.

1. Download memcached.

cd /usr/local/src
wget http://memcached.googlecode.com/files/memcached-1.4.15.tar.gz

2. Install memcached.

tar zxvf memcached-1.4.15.tar.gz
cd memcached-1.4.15
./configure --prefix=/usr/local/memcached --with-libevent=/usr/local/libevent
make
make install

3. Start memcached and check whether the installation is functional

/usr/local/memcached/bin/memcached -d -m 128 -p 11211 -u root

ps aux | grep memcached

memcache is a very practical caching technology. Well-known users of Memcache include: LiveJournal, Wikipedia, Flickr, Bebo, Twitter, Typepad, Yellowbot, Youtube, etc.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/738501.htmlTechArticleAfter the recent increase in website traffic, the number of database connections has been on the high side. After analysis, it is found that they are all normal requests, but The functions of the website are divided into details, and there are too many database query sentences on a single page. A lot of data is...
Statement:
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