Sunday, April 17, 2016

Creating a Web Page Pinging Tool with LiveCode to Check a Web Site's Status

Recently, I've been experiencing a lot of trouble with my web hosting company. I won't identify the company... yet ... as I think they may have finally solved the problem. But, suffice it to say that the problem was chronic and severe to the point that I was considering dropping this company after about 10 years of being a loyal customer. The problem was that my web site was experiencing frequent, intermittent periods of down time. Everything was working fine one minute, then the next I was getting the message "Service Unavailable." Two minutes later, all was fine. To the company's credit, each time I submitted a problem ticket they got on it right away and reported back within an hour or two that they had "found the problem and fixed it." To their discredit, they hadn't. I was submitting help tickets over and over with the company coming back each time to tell me that now all was well, when it really wasn't.

The seriousness reached its peak for me when my web site failed to work properly during a research session about two weeks ago while using my Q Sort tool. I had been experiencing system outages the day before and the morning of the research session. A few hours before the research session was scheduled to take place, the company reported that they had "really" found the cause of the problem this time and all was well. For the next few hours, it did seem like all was working fine. But, during the roughly 20 minutes of the research session, about half of the participants experienced Internet problems. This research session was done during a graduate class and everyone -- including me -- thought that the problem was likely due to some bug in my software. (I had made major updates to the software in preparation for this research session. Happily, my Q sort tool actually seemed to work perfectly.) There is nothing worse to a researcher than to lose data after all the time it took to arrange and plan the session.

I again reported the problem to the company and again looked they into it and again they said they had fixed the problem. I then traveled to attend the AERA conference in Washington, DC and put this issue on the back burner. But when I returned to Georgia and began working on the web site, I found the site was down -- very frustrating. Again, to the company's credit, they steadfastly looked into the problem. Perhaps due to an angst-filled trouble ticket message, they moved my site to a different "application pool," and so far everything has been working fine. Of course, given my lack of confidence I found myself obsessively checking the web site over and over throughout the day. And then it occurred to me -- I could program my own tool to "ping" the web site repeatedly and review the result later. If the web site wasn't working at some point, I could then share my data log with the company to aid in their troubleshooting.

Lloyd's Web Site Pinging Tool

I created a LiveCode stack that pings a given URL every so many seconds to see if it returns an expected result or an error. It's important to remember that if you ping just any old web page, you are going to get a bunch of HTML code as the result, and probably a lot of it. So, I created a very simple PHP page that pulled one small piece of data from the mySQL database along with the following message: "Ping Successful." I also did not use any HTML formatting, so the result was a single line of text. Getting this result let me know that everything on my site was likely working fine.

I also put a date/time stamp at the beginning of each result line. If there was a problem, this would tell me exactly when and for how long the problem persisted.

The great thing about this little app is that even though I might check the web site manually and find everything was working, given the intermittent nature of the problem the thought quickly entered my head "Sure, it's working now, but just wait a minute!" Seeing a data log that ran all night or all day showing no problems is real evidence that the problem has indeed been fixed.

Here's a screen shot of the program after pinging my site every 15 seconds for just two minutes:

You can enter any URL you want and any time interval you want. When you start pinging, the live data stream is shown in the field "Live Pinging Data." When you stop the pinging, the data are automatically copied and pasted into the field "All Data." If you start pinging again, all the "live data" are cleared out as the new pinging session begins. The phrase "New Session" is added at the beginning of any new pinging data session to make each session's data easier to spot.

How It Works

The main code is in the button "Start Pinging:"

 global varDataURL, varCheckResponses, varTime  
 on checkResponses  
   put the internet date&comma&URL varDataURL after field "log"  
   if varCheckResponses is true then   
    send checkResponses to me in varTime seconds  
    put "New Session"&return&return after field "log2"  
    put field "log" after field "log2"  
   end if  
 end checkResponses  
 on mouseUp  
   put line 1 of field "time to check" into varTime  
   put empty into field "log"  
   put field "URL" into varDataURL  
   put true into varCheckResponses  
 end mouseUp  

I created a custom procedure called "checkResponses" that loops as long as the variable "varCheckResponses" is true.  The loop is based on the "send to me" strategy.

All the button "Stop Pinging" does is set "varCheckResponses" to false.

So Far So Good

I'm happy to report that based on the data collected by my pinging tool, my web site has been completely stable for about 48 hours. I ran my program overnight the first day and for a few hours here and there over the next day. My web site might be -- just maybe -- fixed.

So, for now, I'm sticking with the company.

Oh, one more thing. This problem motivated me to learn how to move mySQL data from one web site to another, something I've never done before. I have a PHP/mySQL web site account on one of the servers at my University, so I was going to move everything there if the problem persisted. I had always wondered how difficult it would be to migrate a mySQL site, but never actually learned the steps.