The user’s browser and the server can maintain a consistent connection thanks to the heartbeat application programming interface (API). The ability to lock posts and provide warnings to users when many users attempted to modify the same post at the same time was one of the initial goals. Another motive was to issue notifications to users when their log-in session had ended.
This so-called “communication” entails regularly transmitting data to the server, which subsequently answers with any data that is deemed relevant. Your plugin will now be able to interact between the server & the browser. Thanks to the API, plugins can attach their data at both ends of the connection.
What Are the Steps to Monitor the Heartbeat API?
You can keep track of the traffic from the heartbeat API by accessing the WordPress dashboard and then looking at the server statistics simultaneously. The traffic that is produced by the heartbeat API may be found by looking at the “admin-ajax.php” page. The majority of businesses, however, do not provide access to real-time server information, and this presents a dilemma.
Examples of Practical Use of the Heartbeat API
WordPress developers use the heartbeat API to carry out normal activities to deliver real-time data by syncing the data that is stored on the server and the dashboard. The following are some of the examples that may assist you in gaining a better knowledge of the heartbeat API:
- When you create or update posts in the editor, an automatic periodic save and any modifications will be made.
- Plugins for e-commerce platforms like WooCommerce provide a dashboard with real-time information about sales.
- This function is used to display a notice on the WordPress admin dashboard.
- Displays the information about locking a post that was written by another author. On websites with several writers, when one author edits a post, other authors will get a notification informing them that the editing author has locked the post.
Why Might This Lead to a Problem?
The heartbeat API makes ajax queries to the server via the “/wpadmin/admin-ajax.php” file. This may cause a high percentage of the hosting server’s CPU to be used due to the enormous requests sent to the server. Your account may be suspended since the server resources are restricted.
The Consequences of Suspending the Heartbeat API
Be aware of the following repercussions before you disable the heartbeat API, regardless of whether you do it via a plugin or by altering the “functions.php” file.
- When using the Classic editor, automatic saving and edits will not operate. This indicates that you will need to manually click the “Save Draft” button to save your work. On the other hand, this will not affect whatsoever on the Gutenberg editor.
- If your connection to the internet is lost while you have the “Publish,” “Update,” or “Save Draft” button pressed inadvertently, the material that you have created online will be erased.
- If any of your installed plugins utilize heartbeat API to update the material from the server, you may not be able to see real-time statistics and information. This might be the case.
Refer to WP Glossary for more such articles.