Keep heroku from falling asleep / idling (even with PHP)

Ruby on Rails Scenario

The easiest way to keep a Rails App from idling is to use New Relic Standard (free), in conjunction with their availability monitoring. You can do this in a couple of ways:

Issue the following command with the Heroku Toolkit

heroku addons:add newrelic:stark

Or, login to your heroku account and provision the addon from there.

Once the New Relic addon is provisioned, go to the new relic control panel. You can get there by logging into Heroku and clicking the New Relic addon within your App’s resources dashboard.

Now, complete the setup instructions provided by new relic.

Once you are connected, do the following:

Go into the new relic dashboard for your app
Hover over ‘settings’ on the main top menu
Click “availability monitoring” in the secondary top menu.
Enter the URL of the app you would like to keep awake / keep from idling

By completing the above steps, New Relic will not only Ping the provided URL, but they will actually consume the page’s content. This will keep the Heroku instance awake and it gives you the option to receive an email if it goes down.

PHP Scenario

Heroku, PHP, and New Relic are not compatible, yet. New Relic requires a standalone daemon to be installed on the underlying web server and unfortunately Heroku does not support the installation of that daemon at this time.

So, we can’t use New Relic to keep the Heroku PHP application from idling.

Enter CloudFlare.

Cloudflare is basically an easy (and free) to configure CDN/Proxy.

How does this keep your Dyno from falling asleep? Cloudflare acts as a cache for non-dynamic content (not HTML), which they frequently refresh throughout the day. These requests will keep your PHP app from idling.

Special ultra obvious statement

Only do this if it is necessary for your dyno to remain active all day. If you’re just running a development version of your production site, there is no reason to keep it spinning all day long. This will help to save resources on Heroku’s end, and will ultimately keep the prices down for everyone.

Leave a Reply

Your email address will not be published. Required fields are marked *