shopify analytics ecommerce

Server Monitoring with PHP

In the internet have so many server monitoring scripts has many features, but if you’re like me, just want get a notice when the server is down, and all are httpd server, you can simply achieve through PHP, for example, you may very simple to check if you can connect the server:

Of course, the above program is very simply, just display the server is Online or Down, and only be check server’s status manually in browser. In fact, if the implementation of PHP automatically via crontab, you can make PHP automatically monitor server and e-mail notification when a problem occurs with the administrator. Alternatively, you can put on the server you want to monitor a small PHP program that will print load average of the system, when the load average exceeds the specified value will auto notify the administrator.

The following two PHP, were placed on the server to be monitored as well as monitoring the implementation of the server, the first server-status.php put in the servers to be monitored:


Then put the following server-monitor.php into monitoring servers, no need in the web directory, because it’s run through on crontab:

Set above server-monitor.php to executable and put in crontab:

chmod +x server-monitor.php
crontab -e

After opened crontab, add this line:

*/5 * * * * /path/to/server-monitor.php > /dev/null 2>&1

It’s finished after save above line to crontab, it’s will automatically run /path/to/server-monitor.php every 5 minutes, when the monitored down, or load average to reach 2, it will send email notification of defined administrator email.

Leave a Reply