In this article, we will share our knowledge on WordPress Heartbeat API. After reading this guide, you will be having full knowledge on Heartbeat API that what it is and how you can limit or control it.
What is WordPress Heartbeat API?
The heartbeat API was introduced by wordpress in version 3.6. When you login to your dashboard then wordpress sends ping requests to your server. The requests are sent in the form of pulses (known as heartbeat) and they are sent based on each action of user.
The heartbeat requests are sent when you edit your posts and save the drafts etc. WordPress Heartbeat API is responsible for logging out you from your dashboard if you remain idle for some period of time.
Many plugins use the heartbeat API and they show you the real time stats of your blog. Have you ever wondered that how wordpress posts revisions work on multi-author blogs?
If 2 authors are working on the same article then as soon as one author does some changes on one post then the same changes are visible to another author as well. This all is being done by wordpress heartbeat api.
How to check WordPress Heartbeat API in action?
• If you want to see the wordpress heartbeat API in action then login to your website’s dashboard on Chrome browser.
• Go to More Tools –> Developer Tools.
• Click Network tab.
• You will notice that your website is sending HTTP POST requests to your server. These all requests originate from wp-admin/admin-ajax.php file.
So we can see that the heartbeat api keeps a significant importance in blogging and wordpress. But it gives problems when it starts sending excessive amount of pulses or requests. In some scenarios, you might experience excessive load on your server and you might get database connection issues.
When excessive requests are being sent from admin-ajax.php file and our servers get bloated then we must disable and control the wordpress heartbeat API.
How to control WordPress Heartbeat API?
There are 2 ways by which we can control the heartbeat api functionality in wordpress website.
1. Disable WordPress Heartbeat API completely
In below cases, you can disable the heartbeat api completely.
• Your site is not multi-author blog and you are fine with disabling the heartbeat functionality.
• Although you have multiple writers on your blog but they all work on the different articles. Also, you can live without the features that heartbeat offers.
To disable the heartbeat completely, follow below steps:
• Go to Appearance –> Themes –> Editor.
• Open your theme’s functions.php file.
• After the opening
• After clicking on the desired locations, click on Save Changes.
• Similarly, if you want to allow the heartbeat for a particular location then you can achieve that with Allow Heartbeat.
• For limiting the execution frequency, click on Modify Heartbeat. You will see there a slider which can be dragged from 15 to 300 seconds. If you set it at 90 seconds then it means that the requests from browser to server will initiate in 90 seconds. We have set it to 90 seconds and selected all locations (WordPress Dashboard, Frontend and Post editor).
• The Heartbeat Control plugin lets you define various rules. You can add multiple rules. Suppose you want to set the execution timings to 60 seconds for dashboard, 80 seconds to frontend and 100 seconds to post editor then you can set multiple rules accordingly.
• If you want to remove a particular rule then you can do that by clicking on button Remove Rule.
• If by mistake or deliberately you choose multiple locations in your different rules then the higher priority rule gets precedence. You can sort the rules based on priority that you set. In order to set the rules according to priority, use the up and down arrow keys so that highest priority rule comes first in sequence.
I hope now you know that why and how to control WordPress Heartbeat API.