In 2013, WordPress introduced Heartbeat API–, a feature that allows your browser to automatically communicate with the server. However, this feature has several disadvantages.
if you use a shared host plan, you need to carefully look at the CPU usage of the server. That’s because some hosting companies may suspend your account when you exceed the limit.
here, we will discuss why WordPress Heartbeat API is a common suspect causing problems, and how to disable and modify Heartbeat API frequencies.
what is WordPress Heartbeat API?
WordPress Heartbeat API provides a communication protocol between the browser and the server using AJAX calls. As the name implies,
sends continuous pulses and triggers events (or callbacks) when data is received by API. This feature helps you synchronize all data between the server and the WordPress dashboard. The idea behind
Heartbeat API is very compelling. For example, when you create / edit articles from an editor, it provides the ability to save articles automatically on a regular basis. In the collaborative WordPress site,
has a post-lock feature to prevent you from editing articles that other users are working on. If you use an e-commerce plug-in, this API will also help show what is happening on your site. Why does
restrict WordPress Heartbeat API? Although it is beneficial for
to have auto-save function and real-time data notification function, it may be harmful under certain circumstances.
Heartbeat API uses the / wp-admin/admin-ajax.php file to send AJAX requests (POST requests). Each request to execute the PHP file is equal to the CPU time on the server.
this can cause a large number of requests to be sent to the managed server, resulting in excessive CPU usage.
as we mentioned earlier, this can be a problem for webmasters with shared hosting plans. When you reach the quota limit, high CPU usage will eventually cause the account to suspend.
so, if you encounter a problem that leads to a spike in POST-admin-ajax.php, here is a tutorial that can help you solve this problem. Things to consider before
stops Heartbeat API
if you plan to stop Heartbeat API completely, you need to think twice. It’s not because you can’t do it, but because it’s impractical.
without WordPress Heartbeat API, if you forget to click the Save draft button, all changes you made in the article will be lost. You will no longer be able to access the revision feature in WordPress.
if you install the WordPress plug-in that uses Heartbeat API, you will not be able to display real-time notifications and information on your site.
however, if you are working alone and all of these features are not important to you, you can continue to stop WordPress Heartbeat API.
otherwise, you might consider controlling API instead. How does
use plug-ins to restrict WordPress Heartbeat API?
you can use the Heartbeat Control plug-in to control how often Heartbeat API sends callbacks to your server. After
installs and activates the plug-in, go to Settings-& gt; Heartbeat Control Settings. Here, you can set certain rules for API.
- Heartbeat Behavior- allows you to enable, disable, or modify the heartbeat
- Location- determines the area where you want to control API, and it gives you three options: WordPress dashboard, front end, and article editor
- Frequency- the number of callbacks you allow for each location. Values range from 15 to 300 seconds
. In the example, we limit the frequency of the Heartbeat API function in Post Editor to 200 seconds. This is a more practical approach if you have multiple authors working on the same WordPress site.
you can also set different values at each location you want to control. Simply click the add another value button and adjust accordingly.
the plug-in also allows you to disable WordPress Heartbeat API completely. You can do this by selecting Disable Heartbeat for Heartbeat Behavior. How does
stop Heartbeat API completely without a plug-in?
you can also stop Heartbeat API without a plug-in by adding this code snippet to your active theme functions.php file.
add_action( 'init', 'stop_heartbeat', 1 ); function stop_heartbeat() { wp_deregister_script('heartbeat'); }
remember that if you are the only staff member of the site and you do not need to install other plug-ins that use this API, you should do so.
goes from your WordPress dashboard to Appearance-& gt; Theme Editor. Make sure you are editing the active theme of the site. Click the theme function (functions.php) from the navigation menu on the right. Paste the above code snippet after the & lt;?php tag, and then click Update. This is the case with
, and now you have successfully disabled WordPress Heartbeat API on your site.
Summary
you have learned about WordPress Heartbeat API and the features it provides for your site. While this is undoubtedly beneficial, in a shared hosting environment, it can cause considerable problems if you don’t handle it properly.
to reduce CPU usage on the server, you can control API or disable it altogether. In addition, you can add code to the functions.php file using plug-ins or manually.