HOWTO: Status Check for a Website Database

by

Site-Offline-Plugin

Many people know about services that allow you to ping your website to be sure it’s always online. The idea behind those is that they check every 5/10 mins sending a GET request to the given website and if they get an answer 200 they send you an email.

If you have a website that is based on a database, for example a WordPress blog, sometime you need to check the status of both. It can happen that the website is ON but the database behind is not. In this case you wouldn’t receive any email but users would not be able to access correctly to see the content. It happened to me, while trying to access to some websites, to see the following screen:

error-establishing-a-database-connection

How to avoid this? I want to show how to set up the free service called StatusCake to check if your WordPress database is on. Here are the steps you need to do:

  1. Make an account on StatusCake.
  2. Create a PHP file which connects to the database and returns a 404 response if the db is offline.
  3. Set up StatusCake to ping the file.

I am going to skip the step one, because the registration is pretty straightforward.

The second step consists in uploading a file called db-test.php on your website. Such a file has the following lines of code:

<!DOCTYPE html>
<html>
 <head>
  <title>DB TEST: <?php echo $_SERVER['SERVER_NAME']; ?></title>
 </head>
 <body>
  <?php
   try {
    $PDO = new PDO('mysql:', 'username', 'password');
   } catch(PDOException $e) {
   http_response_code(404);
  }
  echo "DB status : OK";
 ?>
 </body>
</html>

The php code tries to connect to the database with a username and password. If it fails, it returns an error 404 (the http_response_code function is available in PHP > 5.4), otherwise it shows the message ‘DB status : OK’.

Now we can set up StatusCake to ping the file we just created.

Screen Shot 2015-02-11 at 4.54.16 PM

Select ‘Create new test’ and add the URL you just created to the ‘Website URL or IP’. Add your email to ‘Contact Group(s)’ and leave all the other settings to the defaults.

I also recommend to add an extra check to see if the rest of the website is online. To do so simply make another test where you insert your website URL in the ‘Website URL or IP’ field.

If you have done everything correctly you will receive the following email whenever your database is offline:

Screen Shot 2015-02-11 at 4.51.26 PM

Finally, you can use your creativity to tune this trick (of sending a 404 error) for any event you want to monitor. I hope this helps improve your website monitoring efforts.

 

Internet Cryptography Demystified

by

people_talking

About cryptography

While going through a set of configurations to connect on a remote machine I was asked to upload my public key and I realized that I didn’t really know what that was for. If you are asking yourself the same question, or need to convince your mom she can safely use her credit card online, here is brief summary of what’s going on behind the curtains.

Drinking The Koolixir – Part 1

by

erlang-the-movie

In case you haven’t yet heard of it yet, Elixir is a functional programming language (technically, a collection of macros) written in Erlang. I have been persuaded to add it to my (and, consequently, Grio’s) technical repertoire due to a good amount of recent buzz in the blogosphere (as well as some points I’ll get to later). To make sure I have a strong foundation for my Elixir learning experience, I am starting my adventure with a foray into the underlying syntax of Erlang.

Building Better Products with UserTesting

by

Usability

Grio Design is showing some blog love this week! We’ve been busy making clients happy by solving wicked design problems and producing beautiful interfaces, but I wanted to take some time to talk about user experience design (UX), usability, and how UserTesting can help everyone reap the benefits of usability testing.

Meteor

by

meteor-620x460

For the past year, I’ve been working mainly with AngularJS and before that Ruby on Rails. I’ve never heard of Meteor until a few weeks ago. I am intrigued by the idea of tightly connecting the client and server together in a synergistic manner that allows for fast responsiveness, which is what Meteor is all about. I decided to go through Meteor’s tutorial online and get a feel for why the framework differentiates itself from other current technologies. From a very high level perspective, Meteor is a very good solution for quickly building an application from the ground up and provides some cool features out of the box.

Frontend Resolutions for 2015

by

logo_JavaScript

It is a new year and I can exploit that to write a post proclaiming how
something ought to be done in 2015. We can use the new year to discard last year’s practices and mistakes as “the old way” and start fresh from lessons that we’ve learned.

The interesting (and also most frustrating) part about building frontend apps is
how fast the landscape changes. The tools, libraries, and frameworks that you
use today might not be the same as what you’d end up using on a new project only
a month from now. While we’ve ended up with this culture of adopting something
new as soon as someone posts that the “old” way is “dead”, I’ve found a few
pieces of the frontend stack that I do not plan on switching out anytime soon.

I would also like to preface this with stating that this post is highly
opinionated. The opinions expressed here are mine and formed through my own
experiences. These opinions may not reflect what I end up doing in practice, nor
does it reflect on what others at Grio may choose or use.

Continuous Integration: An Overview

by

integration_bot

Continuous Integration at Grio

In the same way that testing code is more and more becoming table stakes for modern software projects, continuous integration is increasingly becoming standard on projects of any non-trivial degree of complexity. Here at Grio, we leverage continuous integration whenever possible, in order to eliminate time spent performing routine deployments and tracking down integration issues.

Creating a Private CocoaPod

by

cocoapods

On a recent project I was tasked with creating a private CocoaPod to be used by several internal iOS applications. As I did my research to do this, I found that the information was spread across several sites and not 100% clear (the CocoaPods site’s documentation could use some love in places). I am taking this opportunity to assist those that follow to create, organize, test and distribute a private Pod. I’ll also throw in a few tips for general pod development.

Git Merge Workflow on Github

by

rebase_5

How to Merge Code

Below is a guide that I wrote for a recent project explaining a git merge workflow on Github. Often times, when you develop a new feature, you will create a new branch off of master called a feature branch. On the feature branch, you might have many commits to save your progress, or when you complete certain milestones of that feature. Once you finish the feature, you will want to merge this branch back to the master branch. However, you might not want all your commits to show up in the git log history because they were only for development purposes. We can overcome this issue by using a feature of git called interactive rebasing which allows you to squash certain commits and customize the commits that will eventually show up once the branch is merged to master. I have described the steps to achieve this outcome below.

Table of Contents

Purpose

This guide explains how to develop and commit your code using git and GitHub. A developer should create a feature branch when developing new code. In the feature branch, a developer may commit multiple times during development including making changes based on comments from a code review. When development is completed and the feature branch is ready to be merged in to the master branch, the developer should squash the commits in to one, so that the git log history is kept clean.