Actually,
I think my code should be used because it gives much more information
about the current status of the web server. A web server isnt just UP or
DOWN. There are many things that can be going on which would cause an
error. The server could be "Too Busy", you could get a bad VirtHost and
Permission Denied Directory listing, if you calling a specific target
there could be a 404 error.
Also, my code only did a HEAD request. The user indicated that he did not
want to perform a GET. With a GET request you have to receive the HTML
data associated with GET "/", which could be 2 Kb or as much as 8 Kb
depending on the site, or even more. If you were writing a script
that was to check 1000's of sites, would you want to be transferring all
that data if you didnt have to.
Look at Google, once they index a site into their databases, they no
longer do GET requests to check the status of index pages, they use HEAD.
Google doesnt want to transfer millions of Kb that it doesn't have to.
John Von Essen
On 31 Oct 2002, Randal L. Schwartz wrote:
> >>>>> "Www" == Www <[EMAIL PROTECTED]> writes:
>
>
> Www> Here is the Code:
>
>
> Www> #!/usr/bin/perl
>
> Www> use LWP::UserAgent;
>
> Www> my $ua = LWP::UserAgent->new(env_proxy => 1,
> Www> keep_alive => 1,
> Www> timeout => 30,
> Www> );
>
> Www> $request = HTTP::Request->new('HEAD', 'http://www.essenz.com/');
> Www> $r = $ua->request($request);
> Www> %b = %{$r};
>
> Www> foreach $key (keys(%b))
> Www> {
> Www> print "$key: $b{$key}\n";
> Www> }
>
> Here is the Much Simpler Code:
>
> #!/usr/bin/perl
>
> use LWP::Simple;
> if (defined get "http://www.essenz.com") {
> print "The server is up\n";
> } else {
> print "The server is down\n";
> }
>
> If you get a 500 error, the response is undef. If you get
> a good page, the response is the content, which is not undef.
>
> Please don't work harder than you need.
>
>
> --
> Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
> <[EMAIL PROTECTED]> <URL:http://www.stonehenge.com/merlyn/>
> Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
> See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
>