Method 1: enable Memcached in linux
Test Environment: Alibaba Cloud CentOS 5.4 32-bit, and June LNMP one-click installation package configuration environment 1.0.
Install Memcached
Lnmp1.0: Enter the directory after lnmp decompression and execute :. /memcached. sh (this is the built-in installation script of Army brother lnmp. For other self-configured environments, install memcache php extension and memcached automatically after you press enter to confirm.
After installation, you can enable it properly.
Enable Memcached caching in WordPress
Download the WordPress Memcached plug-in, unzip it, upload the object-cache.php to the wp-content directory (not wp-content/plugins /), as a result, WordPress will automatically check whether there is a object-cache.php file under the wp-content directory, and if so, directly call it as the WordPress object cache mechanism.
Note: If multiple WordPress are installed on your server, make sure that each WordPress site uses a different database prefix. If the same prefix, for example, is wp _, a conflict may occur, because the data of each website is cached through the memory, the same prefix will fight!
After memcached Cache is enabled for your WordPress site, you do not need to install database Cache plug-ins such as DB Cache Reloaded Fix.
View Memcached cache conditions
Run the telnet command to check whether the telnet package has been installed.
The code is as follows: |
Copy code |
Rpm-qa | grep telnet |
If yes, the system returns the corresponding version.
The code is as follows: |
Copy code |
Telnet-0.17-41.el5 Telnet-server-0.17-41.el5 |
If not, run the following command.
The code is as follows: |
Copy code |
Yum install xinetd Yum install telnet-server |
Note: The telnet service depends on the xinetd service. Therefore, you must first install the xinetd service. Therefore, we must first install xinetd and then install telnet-server.
Link to the telnet service
The code is as follows: |
Copy code |
Telnet fig 11211 |
If the link is successful, the following will be returned:
The code is as follows: |
Copy code |
Trying 127.0.0.1... Connected to 127.0.0.1. Escape character is '^]'. |
Enter
The code is as follows: |
Copy code |
Stats |
Press enter to view the Memcached cache.
STAT pid 20439 -- Memcached process ID
STAT uptime 179982 -- process running time
STAT time 1382361665 -- current time
STAT version 1.4.15 -- Memcached version
STAT libevent 1.4.13-stable
STAT pointer_size 32
STAT rusage_user 21.916668
STAT rusage_system 40.576831
STAT curr_connections 11
Stattotal_connections 329
STAT connection_structures 23
STAT reserved_fds 20
STAT performance_get 2363348 -- Total number of times data is obtained (equal to get_hits + get_misses)
STAT cmd_set 279971 -- Total number of data sets
STAT 1__flush 0
STAT performance_touch 0
STAT get_hits 2286284 -- the number of data hits, that is, the number of times data is successfully obtained from the Memcached cache.
STAT get_misses 77064 -- no hits
STAT delete_misses 30803
STAT delete_hits 48876
STAT incr_misses 0
STAT incr_hits 0
STAT decr_misses 0
STAT decr_hits 0
STAT cas_misses 0
STAT cas_hits 0
STAT cas_badval 0
STAT touch_hits 0
STAT touch_misses 0
STAT auth_cmds 0
STAT auth_errors 0
STAT bytes_read 574591015
STAT bytes_written 4353057466
STAT limit_maxbytes 67108864 -- total storage size. The default value is 64 MB.
STAT accepting_conns 1
STAT listen_disabled_num 0
STAT threads 4
STAT conn_yields 0
STAT hash_power_level 16
STAT hash_bytes 262144
STAT hash_is_expanding 0
STAT bytes 4717345 -- current storage size
STAT curr_items 5654
STAT total_items 58461
STAT expired_unfetched 17
STAT evicted_unfetched 0
STAT evictions 0
STAT reclaimed 49
END
The hit rate of the above data: 2286284/2363348 = 96.7% indicates that the current hit rate is relatively high.
To clear existing data, run the following command:
The code is as follows: |
Copy code |
Stats reset |
To exit telnet, enter Ctrl +].
The code is as follows: |
Copy code |
Telnet> |
Enter quit to exit.
Method 2: enable Memcached memory cache acceleration using WP Super cache
1. Install Memcached Object Cache
1. WordPress supports Object Cache by default. Therefore, implementing Memcached in WordPress is to use Memcached to write the WordPress Object Cache to the memory and read it directly from the memory next time.
2. WP Super cache has been installed. If your host has installed the Memcached component, you can directly use the Memcached memory cache. First download:
- 1. Wordpress Memcached plug-in: Download Memcached Object Cache
3, download Memcached Object Cache to the local, unzip the object-cache.php inside.
4. Upload it to your Wordpress wp-content. Note that it is not wp-content/plugins/
II. Enable Memcached cache in WP Super cache
1. Upload The object-cache.php, and then enter the Wordpress WP Super cache advanced settings, you can see: using the object cache system to store cache files. (Lab functions)
2. Select "update" and click "WP Super cache" to start the Memcached memory cache. The Message "Memcached cache enabled" is displayed in the content, and no available list is displayed.
III. Enable Memcached cache performance analysis
1. At present, the tribe has changed the static file generated by the original WP Super cache to the Memcached cache. When there is no cache, the database query is 35, and the page loading takes about 1.8 seconds.
2. Memcached memory cache is enabled for WP Super cache, with 15 database queries and less than 1 second page loading.
4. Memcached memory cache effect not enabled
1. When WP Super cache is not installed, 22 queries are displayed on the page, 0.36 seconds.
2. WordPress uses WP Super cache but does not enable Memcached memory cache. The number of queries increases by 3 and the time is reduced by 0.1 seconds.
V. Memcached memory cache summary
1. This article only compares the number of database queries on a page with the loading time of page generation. The effect of Memcached memory cache on WP Super cache cannot be generalized, different host environments have different effects.
2. To improve performance, data stored in memcached is stored in the memory storage space built in memcached. Because the data only exists in the memory, restarting memcached and the operating system will cause all data to disappear.