0

I'm trying to send a http request to an url and check the content of the url using following script. However, by just check whether the content is empty or not can't tell whether a site is working.

#use all required modules here;
my $url = "a url here";
my $timeout = 30;
my ($page_content, $res);
eval{
    alarm($timeout);
    $res = $ua->get($url);
    alarm(0);
}
$page_content = $res->content if $res->is_success;

However, the above can't detect a website problem, for example, I got

Fatal error: Call to a member function FetchRow() on a non-object in /home/world/public_html/index.php on line 290

from the $page_content.

So I add this to check the website:

$page_content = 0 if $page_content !~ m{<html\b.*?>.*?<body\b.*?>.*?</body>.*</html>}si;

My question is: is there a function to check whether a website is working except using the above regular expression checks?

Edited by mike_2000_17: Fixed formatting

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by mitchems
0
my $url="a url";
use LWP::Simple;
my $content = get $url;
die "Couldn't get $url" unless defined $content;

Content will be defined if the url is reachable.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.