Health check and slack notification with PHPđź’ˇ

Smaine Milianni
1 min readDec 25, 2020

--

Everybody wants to build robust applications but as the AWS CTO put it so well: “Everything fails, all the time". This is why, as a professional, you should have an excellent disaster recovery.

When your application is down the sooner you know it, the more you increase your chances of getting back to normal.

The health check consists to ping a server and checks the status code, We will build a PHP script that ping servers and sends notifications to a Slack channel if the server returns a server error (between 500 and 600).

We will use vanilla PHP, the goal is to be able to run our script just with PHP without any framework or extra tools…

1- Configuration ❄️

We should have some parameters:

  • the list of the endpoint we want to check
  • the slack parameters (access token, channel, slack URL)

2- Main script 🤺

The script is very basic, we iterate on the defined endpoint, we ping the server if there is a server error or if the endpoint is not reachable we send a notification

That’s all 🎉

(If you need to monitor your application don’t hesitate to use my work)

--

--

Smaine Milianni

Fullstack Developer- certified Symfony 4,5 and certified AWS Solution Architect - Freelancer - Remote Worker