Every two weeks I send out a newsletter containing lots of interesting stuff for the modern PHP developer. You can expect quick tips, links to interesting tutorials, opinions and packages. Want to learn the cool stuff? Then sign up now!

An easy to install uptime monitor

A few weeks ago we released our uptime and ssl certificate monitor. It’s written in PHP and distributed as a Laravel package. If you’re familiar with Laravel that’s all fine, but if you have no experience with that (kick ass) framework, it’s a bit difficult to get started with using our uptime package. That’s why we’ve released a stand alone version of the package. There’s no Laravel knowledge required to use it. In this post I’d like to show you how easy it is to set up.

Uptime and ssl certificate checks

Let’s first recap what our uptime monitor can do. First and foremost it can perform an uptime check on all your sites. When one of your sites goes down, you’ll get a notification via mail and/or Slack. This is how such a notification looks like:

When your site comes back up you’ll get a notification too.

You can customise various aspects of the uptime check in the configuration file.

The package can also notify you when the ssl certificate of one of your sites will expire of has expired. Here’s how that looks like in Slack.

How to install the monitor app

Installing the uptime monitor is now very easy. Just issue this command on your server:

composer create-project spatie/uptime-monitor-app

That command will pull in a copy of Laravel 5.3 with the laravel-uptime-monitor preinstalled. When it’s done it’ll display some instructions you need to follow to complete the installation

The first thing you’ll need to do is adding this command to your cron table so it’ll run every single minute:

php <installation path>/artisan schedule:run

This will make sure that both the uptime and the certificate check will run regularly.

Next, in order to be notified via Slack you need to create a webhook on the Slack site. The url of that webhook needs to be saved in the notifications.slack key in the configuration.php file in the root of the app.

With that out of the way you’re ready to monitor some sites. Let’s add a monitor for our company site https://spatie.be. Perform this command in the root of the monitor app.

php artisan monitor:create https://spatie.be

The monitor app will now regularly perform an uptime check for that site. Whenever you add an url that starts with https the certificate check will also be performed for that site.

If you run php artisan monitor:list after a few minutes you’ll seen a screen not unlike this one.

Of course you can add as many monitors as you like, behind the scenes the app will use Guzzle’s concurrent requests feature to very quickly check multiple sites at once.

Want to stop monitoring a site for a while, just disable it. If you permanently want to stop monitoring a site, just delete the monitor.

// temporarily stop monitoring the site
php artisan monitor:disable https://spatie.be

// start monitoring it again
php artisan monitor:enable https://spatie.be

// delete the monitor
php artisan monitor:delete https://spatie.be

By default the application will store all monitors in an sqlite database located at database.sqlite in the root of the app. It’ll contain a single table called monitors. Here’s the documentation on which fields it contains and which fields may be manually modified.


We hope this standalone version of the uptime monitor is much easier to use for those without any Laravel knowledge. If you have any questions about it or have an idea on how to improve it, just add a comment below this post, or even better, open up an issue on the uptime-monitor-app repo on GitHub. Be sure to also take a look at this list of packages we previously made.

Freek Van der Herten is a partner and developer at Spatie, an Antwerp based company that specializes in creating web apps with Laravel. After hours he writes about modern PHP and Laravel on this blog. When not coding he’s probably rehearsing with his kraut rock band. He loves waffles and butterflies.