Home > Article > Backend Development > Introduction to nginx memcache caching
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
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.
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 #安装
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
location / { set $memcached_key "$uri"; memcached_pass 127.0.0.1:11211; error_page 404 /callback.php; }
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!