For new bloggers, server resource management is a major issue. Most new blogs are based on cost-effective shared hosts, which is understandable. You want to keep the running costs low.
But there is the obvious downside. Shared hosts have their limitations as they need to distribute the resource among all the hosted sites. Hundreds of sites are hosted on the same IP address, and hosts take every step to ensure that no one site abuses the resources.
So while its cost effective, you must be aware of the potential pitfalls (read: resource heavy stuff) that you need to avoid.
One major resource waster for WordPress blogs is the Heartbeat API. More on what it does later.
You should be more concerned about the problems it can create.
On shared hosts, this can often give you a “connection error” message on WordPress.
Even worse, this connection error due to Heartbeat API overusage can prevent you from editing your posts. It will give a message on these lines
Connection lost. Saving has been disabled until you’re reconnected. We’re backing up this post in your browser, just in case.
Connection lost error due to heartbeat api
How to identify a Heartbeat API based issue?
You can roughly identify a case of Heartbeat API based issue by monitoring your admin-ajax.php usage.
Just run a site speed test on Pingdom and check the amount of time spent on admin-ajax.php. If there is indication of heavy admin-ajax.php usage, heartbeat API may be the culprit. In fact, your webhost may even notify you about excess resource usage through admin-ajax.php
The purpose of this API is to simulate bidirectional connection between the browser and the server. Initially it will be used for autosave, post locking and log-in expiration warning while a user is writing or editing.
The idea is to have a relatively simple API that sends XHR requests to the server every 15 seconds and triggers events (or callbacks) on receiving data. Other components would be able to “hitch a ride” or get notified about another user’s activities.
In the future this can be used to block simultaneous editing of widgets and menus or any other tasks that require regular updates from the server.
Basically, the admin-ajax.php is used to make AJAX based connections to the server, directly from your web browser. In layman’s terms, this keeps the server side and admin user side in sync. Any changes on the admin side are automatically notified to the server on a periodic basis. Posts get auto saved, login expires after certain amount of time and so on.
Sounds great on paper!
What is the problem with Heartbeat API on shared hosts?
The major issue here is that Heartbeat API is very resource intensive. This does not go well with the fact that resource is the limiting factor on shared hosts.
In fact, every open backend page contributes to communication between server and the browser. Continuous pulse updates are shared between the server and the user, even if the backend is minimized in your browser. This causes unnecessary load on the server. If multiple users are logged in to the backend, this can lead to very high resource usage. Even if a single user keeps multiple pages open, this can lead to a lot of unnecessary resource usage.
What’s the solution? Should you disable it completely?
Although it is resource intensive, it contributes to essential functions like auto save feature. Better idea is to use it in a controlled manner so that essential functions are not compromised.
Use the drop down to set “Control heartbeat locations” to “Allow only on post edit pages”. This disables Heartbeat API everywhere but post edit pages. This keeps the auto save functionality intact without the slowdown effect from other pages.
Next, use the drop own to “override heartbeat frequency” to “60 seconds”. This overrides the default value and sets the Heartbeat API usage frequency to 60 seconds. This ensures that requests are sent to the server only after an interval of 1 minute. This prevents unnecessary frequent requests being sent to the server and thus reduces server usage.
Also, make sure that you do not keep multiple “post edit pages” open at the same time. If multiple pages are open, each of them would send multiple POST requests. This would put unnecessary pressure on the server and it is best to avoid it.
So there you go. I have given you the easiest way to control the heartbeat API and prevent unnecessary load on your server. I hope this would help you with the “connection lost” problem in the post edit pages. It worked for me!
Let me know if this solves the issue for you. If you face any problems or have further suggestions, please feel free to share in the comments sections.
And please give it a share if you found this solution useful. I am banking on you to spread the word.
Get more stuff like this in your inbox
Subscribe to my email list and get interesting stuff and updates to your email inbox.
Thank you for subscribing.
We respect your privacy and take protecting it seriously