PHP Script to monitor Apache/php-fpm

I moved a web site to new dedicated server. But for some reason, php-fpm crashed. I increased the max_children settings, but it happend again. I do not want down time while i am investigating the problem. So i created a PHP script, that will check if site is working or not.

Script have 2 part.

health-check.php

It is simple PHP script, that get a param and print it.

This file is placed on root of your web site, so it can be accessed using URL http://yoursite/health-check.php

monitor-server.php

Create

Add following content

On the script, replace YOUR_DOMAIN_HERE with your actual domain name.

systemctl restart apache2 is for restart apache web server. If you use nginx, replace it. systemctl restart php7.2-fpm restart php-fpm, if you have differnt version of php, you need to change it.

The script is generate a random number, pass it to health-check.php script. Compared the value returned with generated random number to make sure the value is correct. If web server or php-fpm fail, this check will fail.

Now set a cronjob

Add

Related Posts

Server Monitoring

Add a Comment

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