• 首页
    • English
    • 中文
  • 关于我们
  • 服务项目
    • 谷歌SEO服务
    • WordPress建站服务
    • 谷歌ADS/SEM代运营
  • 项目案例
    • 医疗
    • 建材
    • 机械加工
    • 照明
    • 电商
    • 电脑硬件
  • 博客
    • 服务器运维
      • aliyun
      • 服务器安装
      • 宝塔面板
      • 虚拟化
      • 阿里云
      • Centos
      • linux
      • nginx
    • 电子商务
    • 免费资源
    • PHP
      • Magento
      • WordPress
    • 大数据采集
    • Python
    • Javascript
    • SEO
    • 未分类
  • 联系我们
What's Hot

机械模具加工公司网站设计案例

24 10 月, 2023

快速原型公司案例

24 10 月, 2023

陶瓷加工网站案例

24 10 月, 2023
Facebook Twitter Instagram
  • 中文
  • English
Facebook Twitter Instagram
VPSEO VPSEO
  • 首页
    • English
    • 中文
  • 关于我们
  • 服务项目
    • 谷歌SEO服务
    • WordPress建站服务
    • 谷歌ADS/SEM代运营
  • 项目案例
    • 医疗
    • 建材
    • 机械加工
    • 照明
    • 电商
    • 电脑硬件
  • 博客
    • 服务器运维
      • aliyun
      • 服务器安装
      • 宝塔面板
      • 虚拟化
      • 阿里云
      • Centos
      • linux
      • nginx
    • 电子商务
    • 免费资源
    • PHP
      • Magento
      • WordPress
    • 大数据采集
    • Python
    • Javascript
    • SEO
    • 未分类
  • 联系我们
VPSEO VPSEO
Home»Wordpress»使用memcached来加速WordPress网站的正确方法
Wordpress

使用memcached来加速WordPress网站的正确方法

chrispengcnBy chrispengcn7 8 月, 2021没有评论2 Mins Read
Facebook Twitter Pinterest LinkedIn Tumblr Email
Share
Facebook Twitter LinkedIn Pinterest Email

memcached是什么?

Memcached 是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载。它通过在内存中缓存数据和对象来减少读取数据库的次数,从而提高动态、数据库驱动网站的速度。Memcached基于一个存储键/值对的hashmap。

使用memcached来加速WordPress网站的正确方法-芊雅企服

memcache又是什么?

memcache是一套分布式的高速缓存系统,由LiveJournal的Brad Fitzpatrick开发,但目前被许多网站使用以提升网站的访问速度,尤其对于一些大型的、需要频繁访问数据库的网站访问速度提升效果十分显著。

最简单直白的理解:memcached是memcache的强化版本!

所以,我们本篇主要说的是:使用memcached来加速wordpress网站!

我们一般使用比较简单的直接yum安装了

#Centos直接使用yum安装即可,其他系统自行搜索安装命令,比如ubuntu
yum -y install memcached

#启动memcached
service memcached start

#开机启动
chkconfig memcached on

 

然后集成php-memcached拓展,这些教程百度千篇一律,都有,本文不作介绍。正确安装完成后,服务器就支持环境就已经支持

memcached缓存了。

下面我们在WordPress中怎么来使用这个神器:

1、安装插件

一定要访问github项目页面下载插件包(一定要这个插件!!!):

https://github.com/tollmanz/wordpress-pecl-memcached-object-cache

下载并解压得到的 object-cache.php,上传到 wp-content 目录即可开启memcached缓存。

WordPress官网上的object-cache.php虽然也号称Memcached 插件,然而它只支持Memcache,不支持Memcached,所以不能使用。如果错误地将object-cache.php和Memcached混用的话,则会出现WordPress打不开,前台后台页面一片空白的现象。

 

这也就是经常有人反馈WordPress启用memcached功能后,页面空白,memcached 500错误的错误原因了。所以,我们最重要的是

memcached插件一定要使用对。

 

  1. Now that the server dependencies are resolved, the rest of the configuration is in the WordPress application. Take the object-cache.php file and place it in your wp-content folder. For instance, if the root of your WordPress installation is at /srv/www/wordpress, the location of object-cache.php would be /srv/www/wordpress/wp-content/object-cache.php. Please note that object-cache.php is a WordPress drop-in. It is not a regular plugin or an MU plugin. Drop-ins are located directly in the wp-content folder.
  2. Add the following to your wp-config.php file:
    global $memcached_servers;
    $memcached_servers = array(
        array(
            '127.0.0.1', // Memcached server IP address
            11211        // Memcached server port
        )
    );

    If your Memcached server is located on a different server or port, adjust those values as needed. If you have multiple Memcached instances, add additional servers to the array:

    global $memcached_servers;
    $memcached_servers = array(
        array(
            '1.2.3.4',
            11211
        ),
        array(
            '1.2.3.5',
            11211
        )
    );
  3. To test the WordPress object cache setup, add the following code as an MU plugin:
    <?php
    $key   = 'dummy';
    $value = '100';
    
    $dummy_value = wp_cache_get( $key );
    
    if ( $value !== $dummy_value ) {
    	echo "The dummy value is not in cache. Adding the value now.";
    	wp_cache_set( $key, $value );
    } else {
    	echo "Value is " . $dummy_value . ". The WordPress Memcached Backend is working!";
    }

    After adding the code, reload your WordPress site twice. On the second load, you should see a success message printed at the top of the page. Remove the MU plugin after you’ve verified the setup.

Authors

  • Zack Tollman
  • 10up
Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
chrispengcn
  • Website

Related Posts

如何在wordpress中使用Elementor编辑器显示WooCommerce产品SKU

27 6 月, 2023

WooCommerce 教程:在类别页面中显示产品自定义字段

12 1 月, 2022

Varnish 5.1 & WordPress 带来内存级加速

9 1 月, 2022

Nginx wordpress 二级目录与二级域名泛目录配置方法

7 8 月, 2021
Add A Comment

Leave A Reply Cancel Reply

*

code

导航
  • 首页
  • 关于我们
  • 服务项目
  • 项目案例
  • 博客文章
  • 联系我们
博客
  • 服务器运维
  • 服务器安装
  • nginx
  • PHP
  • WordPress
  • Python
  • Javascript
  • SEO
  • 电子商务
  • 大数据采集
  • 宝塔面板
  • 数据库
  • 电子商务
  • 虚拟化
  • 阿里云
导航
  • 首页
  • 关于我们
  • 谷歌SEO服务
  • 谷歌ADS/SEM代运营
  • WordPress建站服务
  • 项目案例
  • 博客
  • 联系我们
最新文章
  • 机械模具加工公司网站设计案例
  • 快速原型公司案例
  • 陶瓷加工网站案例
  • CNC数控加工日文网站案例
  • 触摸一体机数字标牌厂家网站案例
关于我们
关于我们

广州纬来科技有限公司
联系地址:广东省广州市番禺区富华中路富源二街18号合和大厦809

QQ : 13602156
Email : 13926026058@139.com
Contact: +86 13926026058

Facebook Twitter YouTube LinkedIn
© 2025 广州纬来科技有限公司 粤ICP备2023105857号-2
  • 首页
  • 关于我们
  • 谷歌SEO服务
  • 谷歌ADS/SEM代运营
  • WordPress建站服务
  • 项目案例
  • 博客
  • 联系我们

Type above and press Enter to search. Press Esc to cancel.