Routine to check status of URLs

Dave Cragg dcragg at lacscentre.co.uk
Tue May 16 05:19:06 EDT 2006


On 15 May 2006, at 18:38, RGould8 at aol.com wrote:

> If I wanted to write a Revolution script that goes through a list  
> of URLs and
> checks each URL's status, can anyone give me pointers on the best  
> approach?
>
> I was originally attempting to do a "load URL" approach, and then  
> check the
> error that comes back (either OK, or not found, re-direct failure,  
> etc).
> Unfortunately I'm finding that load URL tends to take awhile to get  
> through URLs
> that do not connect.   I thought "load url" was a non-blocking  
> command, but for
> some reason it does freeze the execution of the handler until it  
> gets through
> the bad URLs.

"load url" will block until the socket connection has been made.

It should be possible to get round this by making your load requests  
in a repeat loop that uses "send <message> .. in <time>". However,  
for the type of information you need, you probably don't want to  
download the entire url. There is an http HEAD method that just  
returns the headers that would be returned if you had issued a GET.

Below is a very crude routine for using the HEAD method on a single  
url. (in this case "http://www.lacscentre.co.uk/liburl/index.html")  
It returns the response headers like this in field 1.

HTTP/1.1 200 OK
Date: Tue, 16 May 2006 09:15:02 GMT
Server: Apache/2.0.40 (Red Hat Linux)
Last-Modified: Wed, 19 Apr 2006 09:27:18 GMT
ETag: "3f50ae1-c7d-430d0980"
Accept-Ranges: bytes
Content-Length: 3197
Connection: close
Content-Type: text/html; charset=ISO-8859-1



Perhaps you could fit it into a repeat loop.

Cheers
Dave

----------------------------------------------------------
local pHeaders

on mouseUp
   put "www.lacscentre.co.uk" into tHost
   put tHost & ":80" into tSocket
   put "/liburl/index.html" into tPath


   put "HEAD" && tPath &&  "HTTP/1.1" into pHeaders
   put crlf & "host:" && tHost after pHeaders
   put crlf & crlf after pHeaders

   open socket to tSocket with message "gotSocket"
   put the result into tRes
   if tRes <> empty then
     answer tRes
   end if
end mouseUp

on gotSocket pSocket
   write pHeaders to socket pSocket with message "written"
   put the result into tRes
   if tRes <> empty then
     answer tRes ##or whatever
   end if

end gotSocket

on written pSocket
   read from socket pSocket until crlf & crlf
   put the result into tRes
   put it into tData
   if tRes <> empty then
     answer tRes ## or whatever
   end if
   put tData into field 1
   close socket pSocket
end written




More information about the use-livecode mailing list