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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
lenamtlCommented:
2

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux

From novice to tech pro — start learning today.