WordPress Blog Install Redis cache

Source: Internet
Author: User
Tags benchmark cloudflare wordpress blog install redis



Redis is an open-source, network-enabled, memory-based Key-value storage system, similar to memcached, with extremely high performance, support for more than 100k+ per second read-write frequency, and some large sites such as Iteye (Javaeye) and csdn now use Redis.



Redis provides persistent storage compared to memcached, memcached needs to recreate the cache after restarting the server, and Redis relies on snapshots for persistence, even if the server just starts up without causing a load spike. Redis cache is better suited for high-traffic WordPress.



When your WordPress article reached tens of thousands of articles, with the increase in traffic, WordPress server pressure is also increasing, WordPress published articles and background related operations will become slow, At this point if the single from the hardware input to improve the performance of WordPress is obviously not cost-effective.



Using Redis to cache WordPress pages directly in the server's memory, so that in the avoidance of PHP repeated operations, the memory of the rapid response to maximize the access speed of the WordPress page, The tribal actual test found that the page execution time could be reduced to 0.00X seconds, or more than more than 10 times times more than the Redis cache was not used.






Environment Description: centos6.6 LNMP Environment



Redis official website Download Source: http://redis.io/download


[Email protected] src]# wget http://download.redis.io/releases/redis-3.0.2.tar.gz[[email protected] src]# tar zxvf redis-3.0.2.tar.gz [[Email protected] redis-3.0.2]# CD Redis-3.0.2[[email protected] redis-3.0.2]# make


#redis的安装非常简单, you already have a ready-made makefile file, run the make command directly



after the installation is complete, in the SRC directory, several executables are generated: redis-benchmark,redis-check-aof,redis-check- Dump,redis-cli,redis-sentinel,redis-server. These files, together with a redis.conf, form The final available package for the entire redis.






Below you can copy these executables and redis.conf files to the place you want, such as/usr/local/redis/bin and/usr/local/redis/etc below, command as follows:


[[Email protected] src]# CD Redis-3.0.2[[email protected] redis-3.0.2]# mkdir-p/usr/local/redis/{bin,var,etc}[[email Protected] redis-3.0.2]# CD Src/[[email protected] src]# cp redis-benchmark redis-check-aof redis-check-dump redis-cli re Dis-sentinel Redis-server/usr/local/redis/bin/[[email protected] redis-3.0.2]# cp/usr/local/src/redis-3.0.2/ Redis.conf/usr/local/redis/etc[[email protected] redis-3.0.2]# ln-s/usr/local/redis/bin/*/usr/bin/


To modify the redis.conf configuration file:


[[email protected] redis-3.0.2]# sed-i ' s#pidfile.*$ #pidfile/var/run/redis.pid# '/usr/local/redis/etc/redis.conf [[ Email protected] redis-3.0.2]# sed-i ' s#logfile.*$ #logfile/usr/local/redis/var/redis.log# '/usr/local/redis/etc/ redis.conf [[email protected] redis-3.0.2]# sed-i ' s#^dir.*$ #dir/usr/local/redis/var# '/usr/local/redis/etc/ redis.conf [[email protected] redis-3.0.2]# sed-i ' s#daemonize no#daemonize yes# '/usr/local/redis/etc/redis.conf


Note that the Daemonize parameter for the default copy of the past redis.conf file is no, so Redis does not run in the background, so we need to reopen a terminal to test it. Modify to Yes to run Redis in the background. In addition, the configuration file specifies the address of the PID file, log file and data file, if necessary, the default log information is directed to standard output.


[[email protected] redis-3.0.2]# echo ' vm.overcommit_memory = 1 ' >>/etc/sysctl.conf [[email protected] redis-3.0.2 ]# sysctl-p


Configuring the Boot Boot Redis-server


[Email protected] src]# wget https://raw.githubusercontent.com/lj2007331/lnmp/master/init/ Redis-server-init-centos[[email protected] src]# mv Redis-server-init-centos/etc/init.d/redis-server[[email Protected] src]# chmod +x/etc/init.d/redis-server [[email protected] src]# chkconfig--add redis-server[[email protected ] src]# chkconfig Redis-server on


Start Redis


[[Email protected] src]# service Redis-server start





Test:


[[email protected] src]#/usr/local/redis/bin/redis-cli127.0.0.1:6379> set 123 babyok127.0.0.1:6379> get 123 " Baby "127.0.0.1:6379> exit


Turn off Redis


[[Email protected] src]# service Redis-server stop


Installing the Redis PHP client


[[email protected] src]# wget http://pecl.php.net/get/redis-2.2.3.tgz[[email protected] src]# tar zxf redis-2.2.3.tgz [[ Email protected] src]# CD redis-2.2.3



Execute the phpize command to generate the Configure executable file


[Email protected] redis-2.2.3]#/usr/local/php-fpm/bin/phpize [[email protected] redis-2.2.3]#./configure-- with-php-config=/usr/local/php-fpm/bin/php-config [[email protected] redis-2.2.3]# make && make install


PHP.ini configuration file, adding extension


[Email protected] ~]# sed-i '/; Extension_dir = "ext"/a\extension = "redis.so" '/usr/local/php-fpm/etc/php.ini [[email protected] ~]# service PHP-FPM Res Tart





Enable WordPress to support Redis



You need a client development package so PHP can connect to the Redis server, where we recommend Predis. Join the WordPress root directory and perform the following


[Email protected] src]# wget http://uploads.staticjw.com/ji/jim/predis.php[[email protected] src]# chown PHP-FPM: PHP-FPM predis.php


Front-End cached PHP script, added to the WordPress root directory, perform the following


[Email protected] src]# wget https://gist.githubusercontent.com/JimWestergren/3053250/raw/ D9e279e31cbee4a1520f59108a4418ae396b2dde/index-with-redis.php[[email protected] src]# chown PHP-FPM:PHP-FPM index-with-redis.php [[email protected] src]# MV predis.php Index-with-redis.php/data/www/blog


Modify the index-with-redis.php to suit your needs, as follows:


$CF = 0;                     Set to 1 if you is using Cloudflare$debug = 1;  Set to 1 if you wish to see execution time and cache Actions$display_powered_by_redis = 0; Set to 1 if your want to display a powered by Redis message with execution time, see below


If you are using CloudFlare, please set CF = 1; ,



If you want to see the script execution time and cache load time on the page, set $debug = 1; At the bottom of the browser, this is cache appears:



Display_powered_by_redis = 1 indicates that the powered_by information is displayed. As in the lower right corner icon:



650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/ Images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/>650 "this.width=650;" src= "http ://s3.51cto.com/wyfs02/m00/6f/96/wkiom1wigahbb7v1aabyojyiy64741.jpg "title=" redis.jpg "alt=" Wkiom1wigahbb7v1aabyojyiy64741.jpg "/>



Replace index.php


[[Email protected] blog]# mv index.php index.php.bak[[email protected] blog]# mv index-with-redis.php index.php


Caching issues



Comments in index-with-redis.php


-Appending a? c=y to a URL deletes the entire cache of the domain, only works if you are logged in-appending a? r =y to a URL deletes the cache of this url-submitting a comment deletes the cache of that page-refreshing (F5) a Page deletes the cache of that page


Sign in to the background website URL and add the c=y to refresh the entire site.



Can be manually refreshed by adding the R=y to the site page.



Submitting a comment will automatically refresh the page



Refresh (F5) page can also refresh page



Refresh Web page view cache effect, view source code



 browser page The bottom corner will appear similar to the following: This is a cache:0.04534



F5 Refresh page Cache time will change






Precautions



1, note that the Wordpress Redis cache PHP version above 5.3



2, the WordPress Redis cache acceleration effect is undoubtedly obvious, special pages more access to large Web site blog, when using the WordPress redis cache acceleration, please prohibit all other cache plug-ins, so as not to cause unnecessary conflicts.






This article is from the "Model Student's Learning blog" blog, please be sure to keep this source http://mofansheng.blog.51cto.com/8792265/1673829



WordPress Blog Install Redis cache


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.