How to configure Memcached caching to speed up the pace wordpress

What is Memcached

Memcached is a high performance, distributed memory object caching system. In dynamic applications, Memcached both increase the speed of access, but also reduce the load on the database. DangaInteractive to enhance the speed of LiveJournal.com developed Memcached. Currently, LiveJournal.com already providing up to two million times the page views to one million users a day. And these, by a by a Web server clustering and database servers is completed. Memcached almost completely abandoned any way to read data from the database at the same time, it also shortens the user to view the page's speed, better resource allocation, and when Memcache access failure rate of the database.

WordPress supports Memcached it

Yes, WordPress default support ObjectCache, is achieved using Memcached Memcached is written to the memory of WordPress ObjectCache go in WordPress, the next read directly from memory. Compared directly to read data from the database, or deposit from ObjectCache data to a file, and then read from the hard disk, Memcached has a great speed advantage.

How to configure Memcached caching to speed up the pace wordpress

We look directly above comparison can be clearly seen in FIG., A cache hit rate after the Memcached object, it can be seen the hit rate is very high, close to 97%, can ensure that substantially all data from the memory can take, so use Memcached caching is very effective.

Memcached service configuration server

1. Memcached server installation, the official website does not provide the Memcached Window platform installation package, we can under the link to download, you need according to their own system platform and version number Clicking on this link to download the required

1.2.5 version of 32-bit systems: https://www.svlik.com/wp-content/uploads/2017/12/memcached-1.2.5-win32-bin.zip

32 System version 1.2.6: https://www.svlik.com/wp-content/uploads/2017/12/memcached-1.2.6-win32-bin.zip

1.4.4 version of 32-bit systems: https://www.svlik.com/wp-content/uploads/2017/12/memcached-win32-1.4.4-14.zip

64 System version 1.4.4: https://www.svlik.com/wp-content/uploads/2017/12/memcached-win64-1.4.4-14.zip

1.4.5 version of 32-bit systems: https://www.svlik.com/wp-content/uploads/2017/12/memcached-1.4.5-x86.zip

64 System version 1.4.5: https://www.svlik.com/wp-content/uploads/2017/12/memcached-1.4.5-amd64.zip

In the previous version 1.4.5 memcached can be installed as a service, but in version 1.4.5 and later removed the feature. Here we are two different versions 1.4.4 and 1.4.5 of the different installation methods:

memcached <1.4.5 version is installed

1, extract download the installation package to the specified directory, the C drive may be a disc D, station C to the root directory for an example, other letter of the operation the same way.

How to configure Memcached caching to speed up the pace wordpress

2、在1.4.5版本以前memcached可以作为一个服务安装,使用管理员权限运行以下命令:

第一步:用win+r打开cmd输入cd c:/进入你解压Memcached所在的盘符

How to configure Memcached caching to speed up the pace wordpress

第二步:再输入cd memcached进入解压盘符的Memcached文件夹

How to configure Memcached caching to speed up the pace wordpress

第三步:再输入memcached.exe -d install安装Memcached为系统服务

How to configure Memcached caching to speed up the pace wordpress

第四步:启动Memcached服务输入memcached.exe -d start

How to configure Memcached caching to speed up the pace wordpress

打开服务器的任务管理器,如果看到Memcached.exe的进程,就说明服务已经启动,每次服务器启动都会自动启动。

同理如果需要停止或者卸载Memcached服务,需要执行以下2条命令

c:\memcached\memcached.exe -d stop //停止Memcached服务 c:\memcached\memcached.exe -d uninstall //卸载Memcached服务

memcached的配置项可以在注册表的如下路径来修改

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\memcached

memcached使用的缓存内存配置修改ImagePath,执行以下命令

c:\memcached\memcached.exe -d runservice -m 512

此外我们还可以通过使用 "c:\memcached\memcached.exe -h" 命令查看更多的参数配置。

memcached >= 1.4.5 版本安装

memcached1.4.5 版本之后,memcached 不能作为服务来运行,需要使用任务计划中来开启一个普通的进程,在 window 启动时设置 memcached自动执行。

我们使用管理员身份执行以下命令将 memcached 添加来任务计划表中:

schtasks /create /sc onstart /tn memcached /tr "'c:\memcached\memcached.exe' -m 512"

删除 memcached 的任务计划可以执行以下命令:

schtasks /delete /tn memcached

到此windows服务器的Memcached配置已经完成,接下来就是配置Memcached的PHP扩展

配置服务器Memcached扩展

官方地址:http://pecl.php.net/package/memcache/3.0.8/windows

貌似目前memcache的windowsphp扩展只支持到php5.6版,对于php7.0版本的我都没有去研究测试,梵天网目前使用的也是php5.6版本,这里有个ts和nts版本的选择,大家可以在网站新建一个phpinfo.php文件,里面加入 <?php phpinfo(); ?>,用浏览器打开这个phpinfo.php,就可以看到网站的php相关信息,打开这个页面。用CTRL+F查找  Thread Safe,如下图

How to configure Memcached caching to speed up the pace wordpress如果显示disabled 那么我们就选择nts版本,如果选择enabled 那么就选择ts版本

顺便普及下ts和nts的区别

Ts与nts的区别:

Windows版的PHP从版本5.2.1开始有Thread Safe和NoneThread Safe之分。

先从字面意思上理解,Thread Safe是线程安全,执行时会进行线程(Thread)安全检查,以防止有新要求就启动新线程的CGI执行方式而耗尽系统资源。Non Thread Safe是非线程安全,在执行时不进行线程(Thread)安全检查。

ISAPI执行php选择ts ,FastCGI执行php请选择nts

将下载好的php_memcache.dll到你php的ext目录下,如果你的服务器是多版本php,请一定选择好你网站的php版本的ext目录下。

再打开php下面PHP.ini进行配置,

在PHP的配置文件中:php.ini 的底部加上以下的代码:

[memcache]
extension = php_memcache.dll

4.重新启动IIS,然后查看一下phpinfo.php,如果有memcache这个项目,那么就恭喜安装成功!

接下来就是全文的重点,wordpress如何配置memcache缓存

wordpress配置memcache缓存

下载 WordPress Memcached 插件:http://wordpress.org/extend/plugins/memcached/

下载好这个object-cache.php 复制到 wp-content,注意不是 wp-content/plugins/。

WordPress 会自动检查在 wp-content 目录下是否有 object-cache.php 文件,如果有,直接调用它作为 WordPress 对象缓存机制。

到此整个教程结束,大楷的总结下 主要三大步

1. 服务器配置memcached服务 2.服务器安装memcached PHP扩展3.下载wordpressd的Memcached插件

Memcached还有其他的一些常用的命令如下

 -p 监听的端口
-l 连接的IP地址, 默认是本机 -d start 启动memcached服务 -d restart 重起memcached服务 -d stop|shutdown 关闭正在运行的memcached服务 -d install 安装memcached服务 -d uninstall 卸载memcached服务 -u 以的身份运行 (仅在以root运行的时候有效) -m 最大内存使用,单位MB。默认64MB -M Memory exhaustion error returned, instead of deleting items - C maximum number of simultaneous connections, the default is 1024 - F block size growth factor, default is 1.25 - n- minimum allocation space, Key + value + the flags default is 48 - H Display help of Origin : https: //www.svlik.com/994.html    

Guess you like

Origin www.cnblogs.com/huangcong/p/10990328.html