I’ve been using Heroku more and more, but not for anything really valuable to me. I mostly use it for hosting one-off projects that are low traffic. A lot of times, it’ll take 30 seconds or so for the site hosted on Heroku to respond, while the Heroku dyno is woken up. If your site goes without any traffic for a certain period of time, it will go to sleep.
Heroku does this to save server resources, which is a logical thing for them to do. Sometimes though, I don’t want to wait to see my site, even if I only have a free account.
I’ve seen a lot of tutorials on how to do this with Ruby, but no language-agnostic way of doing it. I also haven’t seen any way of doing this with PHP. There’s 2 methods you can use to keep your site from going to sleep.
This is the easiest and quickest way to keep your app awake, and is language-agnostic. UptimeRobot is a free service that monitors your sites. When you’re adding a new site to monitor in UptimeRobot, make sure to set the monitor type to “HTTP(s)”. UptimeRobot will check to make sure your site is up every 5 minutes, which will prevent your site from sleeping.
2. Heroku Scheduler
This method is a little more involved, but is probably the Heroku-preferred method.
While you’re viewing your app resources on the Heroku dashboard, click the “Get Add-ons” link. Add the Heroku Scheduler add-on to your app, it’s free.
Go back to managing your app’s resources on the Heroku dashboard, then click “Heroku Scheduler Standard” to manage the Heroku Scheduler for your app. Add a new job, and set the frequency to Every 10 minutes. For your task, enter curl -I http://your-app-name.herokuapp.com. This will fetch HTTP response headers from your app, using Curl, every 10 minutes.
It should be noted that method 2 could potentially cause you to have a balance to pay at Heroku. That’s because Heroku Scheduler has Dyno Hour Usage.
So, there’s two options that everyone can use to keep your Heroku apps from sleeping, no matter what language your app is written in.
Where to now?
Work with Me
Think you'd need help getting somethink like this setup on your own? Or maybe you've got an idea for a product but don't know how to turn it into 'something'. I can help on both fronts! Just get in touch and we can chat about your needs.