SiteCheck

August 25, 2004 at 4:01 pm Leave a comment

For probably a year now I’ve been looking at various tools to be able to verify that web services are up and working properly. Most of these tools offer the ability to “ping” a TCP port, basically to see if it is still up. The nicer ones will also let you perform a “content check” to see if a certain string of text appears on the website you are checking.. Some let you check lots of services (HTTP, SMTP, POP3, etc.) I won’t go into the reasons why, but I’ve finally decided that I absolutely need to be running one of these applications, and I need it right now…

Of course, there is a reason why I don’t have one yet… Cost. People who have written these tools are extremely proud of them.

So, I’ve decided to write my own SiteCheck tool in PHP. Here are the requirements:

1. Must work well on a PC that has a somewhat unreliable internet connection. (Check to make sure internet connection is up)
2. Must be able to check a number of sites.
3. Must be able to send an email whenever a problem is found. (One email should contain all sites that failed that attempt, not 4 emails if 4 different sites failed.)

*tick tock tick tock*
Ok, about an hour of coding and testing later, and I have my first version ready…

I was planning to post at least a portion of it here, but until I get my CMS up and running, or come up with some other “code viewer”, I guess I’ll hold off.

I used two arrays, $inet and $siteToCheck to hold data. $inet is strictly for “stable” sites that you expect to always be up and working… Basically, if you can’t get to any of these sites, your internet connection is not working right. The $siteToCheck array is for the sites you are interested in checking out. The index of these arrays is the URL of the site to check (such as http://www.yahoo.com) and the value of each element is a piece of text that is on the page, such as “Yahoo!”.

A quick function called readWebSite pulls the data in from the remote website and verifies that the “content” is there. If so, you get a true response from this function, otherwise false.

In the main loop of the program, a foreach runs against each element of the $inet array. The first “good” reply tells us that the internet is up, so we set a flag variable accordingly and “break;” out of the foreach loop. No need to check your entire list of “stable” internet sites.

If the Internet is up, we run a foreach against each site in the $siteToCheck array. Any problems are recorded in the $problems variable.

If there were any problems, an email is sent to me to let me know the extent of the issues.

Then, we simply sleep for 15 minutes and repeat…

It would not be too difficult to write a version of this to perform most of your standard communications, as PHP has other protocols that are easily checked, such as SMTP and POP3.

Advertisements

Entry filed under: PHP.

An Important Programming Truth, re-discovered Trim text down for the web

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed


Calendar

August 2004
S M T W T F S
« Jul   Sep »
1234567
891011121314
15161718192021
22232425262728
293031  

Most Recent Posts


%d bloggers like this: