Click to See Complete Forum and Search --> : Ping Script request


hammerslane
02-24-2004, 10:11 AM
Hey people. I've been modifying this script over the space of about 2 months. It's a ping script, which tries to make a connection to the URLs in the array at the top, and echo's whether the fopen was sucessful.

<?php
//URL ARRAY
$links = array ("www.hammerslane.com","www.example.com");

function chkuri($link)
{
$churl = @fopen("http://".$link,'r');
if (!$churl) {
return false;
}else{
return true;
}
}

foreach($links AS $link)
{
if(!chkuri($link))
{
print"$link is down<br><br>";
}
else
{
print"$link is up<br><br>";
}
}

?>

If you go to this address... www.hammerslane.com/pingfo1.php you can see it in action. the obvious thing wrong with it, is that it says both addresses are down... (wrong, otherwise you couldn't visit the page, or this thread).

Can anyone tell me why this is happening? Is there an alteration to the code that I can make?

Many thanks!

pukka
02-24-2004, 10:57 AM
$churl = @fopen("http://".$link,'r');

should be

$churl = @fopen("http://".$link.'r');

I think thats the problem. if not, its definately A problem... i think.

hammerslane
02-24-2004, 11:02 AM
ah - thanks for the reply, but the script still seems to be broken... instead of taking 1 minute to run the script, it now takes under a second, and still says the same thing :(

any other ideas?

pyro
02-24-2004, 12:13 PM
Actually, the only problem with your original code is that you forgot the closing " after you second array item. Your fopen was correct.

hammerslane
02-24-2004, 12:54 PM
okay, i've put the comma in on the fopen an fixed the array.

apparently they're both still down...

pyro
02-24-2004, 01:04 PM
The updated code above works fine for me.

hammerslane
02-24-2004, 05:54 PM
what's the kind of server you're testing it?

hammerslane
03-01-2004, 04:43 AM
sorry to double post... but pyro, what server type did you test the above script on?
because i'm using a windows testing server to no joy.

edit: i'm running the script on a linux now, and it still says they're both down... :(

pyro
03-01-2004, 08:16 AM
I was testing on my local computer - Win XP, Apache 1.3.28, PHP 4.3.3.

Check if allow_url_fopen (http://us4.php.net/manual/en/ref.filesystem.php#ini.allow-url-fopen) is set in your php.ini file. If it is not, then it won't work.

hammerslane
03-01-2004, 08:46 AM
here is what the php.ini file says...
;;;;;;;;;;;;;;;;;;
; Fopen wrappers ;
;;;;;;;;;;;;;;;;;;
allow_url_fopen = On ; Wheter to allow trating URLs like http:... or ftp:... like files