PHP script to monitor websites for downtime

I have a Linux server and I would like a PHP script to monitor a list of websites to check if they are active. For example I would like to check for any websites returning a 500 internal server error. Upon detecting this error I would like an email and SMS notification sent.

I understand the script needs to be called either by a CRON job or internal scheduler on a regular basis such as every 5 minutes.

I wish to reiterate that the websites being monitored are hosted externally on a Windows server but a Linux server will be used to do the monitoring.
mike99cAsked:
Who is Participating?
 
lenamtlCommented:
2
 
Olaf DoschkeSoftware DeveloperCommented:
Why not use existing services? There are plenty out there.
If you insist on redoing that and reject checking uptime from many locations, too. you have several choices, eg

exec("ping -c 1 host",$output, $result)

Open in new window


Where host might be the domain name (www.google.com) or ip address.

Which will give $result values 0:success (up), 1:no reply (down), 2:other errors (state unclear)

To get the HTTP status code you obviously need to do an HTTP request, if you are familiar with cURL and have it installed as php extension then why not use it? Or use it on the shell level again via exec, a Linux server makes this easy.

If you're a novice on the topic of HTTP you might like the simple interface of http://requests.ryanmccue.info/ to make HTTP requests.

Advantages of HTTP vs ping obvious are you can monitor single URLs, could authenticate, if it matters, get more response status codes and more.

Last not least existing services also might offer more in terms of port checks and testing other services than http, too.

Bye, Olaf.
1
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.