集群中heartbeat_如何在WordPress中限制Heartbeat API

集群中heartbeat

WordPress Heartbeat API is a great feature and opens the door to some great possibilities for plugin developers. However in some cases, it can increase your CPU usage and slow down your website. In this article, we will show you how to limit Heartbeat API in WordPress or even completely stop it.

WordPress Heartbeat API是一个很棒的功能,为插件开发人员打开了许多可能性的大门。 但是,在某些情况下,它可能会增加CPU使用率并降低网站速度。 在本文中,我们将向您展示如何限制WordPress中的Heartbeat API甚至完全停止它。

WordPress HeartBeat API

Introduced in WordPress 3.6, Heartbeat API allows your browser to communicate with the server using AJAX calls when you are logged into WordPress admin area. This allows WordPress to show other authors that a post is being edited by another user and enable plugin developers to show you notifications in real-time.

在WordPress 3.6中引入的Heartbeat API,使您的浏览器可以在登录WordPress管理区域时使用AJAX调用与服务器进行通信。 这使WordPress可以向其他作者显示帖子正在由其他用户编辑,并使插件开发人员可以实时向您显示通知。

This sounds great but if you have too many requests, then your server will slow down. Let’s take a look at how to limit or completely stop WordPress Heartbeat API.

这听起来不错,但是如果请求太多,那么服务器将变慢。 让我们看一下如何限制或完全停止WordPress Heartbeat API。

影片教学 (Video Tutorial)

演示地址

If you don’t like the video or need more instructions, then continue reading.

如果您不喜欢该视频或需要更多说明,请继续阅读。

First thing you need to do is install and activate the Heartbeat Control plugin. Upon activation, you need to visit Settings » Heartbeat Control to configure the plugin.

您需要做的第一件事是安装并激活Heartbeat Control插件。 激活后,您需要访问“设置”»“心跳控制”以配置插件。

Settings page for heartbeat control plugin

From the ‘Control heartbeat locations’ option, you can select where you want to control heartbeat settings. You can disable it on dashboard, allow it on post edit pages, or completely disable it everywhere.

从“控制心跳位置”选项中,您可以选择要控制心跳设置的位置。 您可以在仪表板上禁用它,允许在后期编辑页面上使用它,或者在任何地方完全禁用它。

Changing heartbeat api call intervals

The next option allows you to control the frequency of heartbeat. By default, heartbeat makes a post call every 15 seconds on post edit pages, and every minute on the dashboard. You can choose a higher frequency.

下一个选项使您可以控制心跳的频率。 默认情况下,心跳每15秒在帖子编辑页面上和每分钟在仪表板上发出一次帖子呼叫。 您可以选择更高的频率。

Click on the save changes button to store your settings. That’s all you have successfully limited heartbeat API calls on your site.

单击保存更改按钮以存储您的设置。 这就是您成功限制网站上心跳API调用的全部。

在没有插件的情况下禁用WordPress中的Heartbeat API (Disable Heartbeat API in WordPress Without a Plugin)

If you are a single user on your site, and you are sure that you will not be needing any features made possible by the API, then you can disable it. You can use heartbeat control plugin, we mentioned above, or you can simply copy and paste this code snippet into your theme’s functions.php file or in a site-specific plugin.

如果您是站点上的单个用户,并且确定不需要使用API​​可能提供的任何功能,则可以将其禁用。 您可以使用上文提到的心跳控制插件,也可以简单地将此代码段复制并粘贴到主题的functions.php文件或特定站点的插件中


add_action( 'init', 'stop_heartbeat', 1 );
function stop_heartbeat() {
wp_deregister_script('heartbeat');
}

We hope this article helped you learn how to limit heartbeat API in WordPress. You may also want to checkout these tips and hacks to protect WordPress admin area.

我们希望本文能帮助您学习如何限制WordPress中的心跳API。 您可能还想查看这些提示和技巧,以保护WordPress管理区域

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

如果您喜欢这篇文章,请订阅我们的YouTube频道 WordPress视频教程。 您也可以在TwitterFacebook上找到我们。

翻译自: https://www.wpbeginner.com/plugins/how-to-limit-heartbeat-api-in-wordpress/

集群中heartbeat

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值