Introduction to nginx memcache caching

不言
Release: 2023-04-02 14:12:01
Original
1644 people have browsed it

This article mainly introduces the introduction of nginx memcache caching, which has certain reference value. Now I share it with you. Friends in need can refer to it

1 Basically

In a In the lnmp architecture, when nginx encounters dynamic resources, it will reverse proxy and send the request to the back-end php-fpm service. php-fpm reads data from mysql, produces web pages, and then returns it to the client.

If the traffic is large, php-fpm and mysql will become bottlenecks. The solution is to add a memcached cache.

nginx first uses $uri as the key to query the value in memcached. If it hits the value, it will directly return the value to the client. If not, then pass php-fpm. php-fpm returns the data to the client and stores a copy in memcached.

So, here you need the connection between nginx and memcached, and the connection between php and memcached.

2 PHP installs the memcache extension module

PHP does not support operating memcahce and needs to install an interface.

http://pecl.php.net/package/memcacheDownload memcache-2.2.7.tgz

yum install m4 autoconf #安装相关依赖 /app/php/bin/phpize #运行phpize,不然memcache目录下没有configure文件 ./configure --with-php-config=/app/php/bin/php-config #安装扩展模块,使用php-config make && make install #安装
Copy after login

After installation, memcache.so will be generated.

In the php/lib/php.ini file, there is a place for dynamic expansion. Add memcache.so to it and restart php-fpm.

In info.php, you can verify the installation

3 nginx directly connects to memcache

location / { set $memcached_key "$uri"; memcached_pass 127.0.0.1:11211; error_page 404 /callback.php; }
Copy after login

The above is the entire content of this article. I hope it will be helpful to everyone's study. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

How to automatically wrap text and pictures in imagettfbbox and imagettftext in php

PHPstorm configures the PHP code introduced by PHPunit to composer Perform unit testing

The above is the detailed content of Introduction to nginx memcache caching. For more information, please follow other related articles on the PHP Chinese website!

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
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!