Page 1 of 1

PHP Ping Script

Posted: Mon Mar 01, 2004 7:07 am
by hammerslane
Hi folks. I've managed to piece together a php ping script that i THINK should work, but all urls that i ping, it says they are all down.
Here is the code, do you have any idea what's going wrong with it?
I can't link to a result page, because its my local test server, but check at the bottom for a dump of what it tells me.

Code: Select all

<?php
//URL ARRAY
$links = array ("www.hammerslane.com","www.phpbuilder.com","www.linkynoworkyaaaaaaaaaa.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>";
}
}

?>
here is what it outputs...

Code: Select all

www.hammerslane.com is down

&#1111;url]www.phpbuilder.com&#1111;/url] is down

&#1111;url]www.linkynoworkyaaaaaaaaaa.com&#1111;/url] is down
hammerslane.com is up, and obviously, so is phpbuilder.com, yet it says they're both down.

anyone have an idea?
many thanks :)

Posted: Mon Mar 01, 2004 9:21 am
by AVATAr

Posted: Mon Mar 01, 2004 11:26 am
by malcolmboston
poster wrote:

Code: Select all

function chkuri($link) 
{ 
$churl = @fopen
the function you have made and the function being ceho'd are different this could be your problem

Posted: Mon Mar 01, 2004 11:47 am
by ol4pr0
Something somewhat simpler to code .. and use i think

Code: Select all

require 'Net/ping.php';

$ping = new Net_Ping;
if ($ping->checkhost('http://forums.devnetwork.net')) {
   echo "Online";
}
else
{
   echo "Down";
}
$data = $ping->ping('http://forums.devnetwork.net');

Posted: Mon Mar 01, 2004 12:06 pm
by Roja
ol4pr0 wrote:Something somewhat simpler to code .. and use i think

Code: Select all

require 'Net/ping.php';

$ping = new Net_Ping;
if ($ping->checkhost('http://forums.devnetwork.net')) {
   echo "Online";
}
else
{
   echo "Down";
}
$data = $ping->ping('http://forums.devnetwork.net');
You failed to mention where to get the 'Net/ping.php' class, which is what makes your example 'simpler'. Is it part of Pear?

Posted: Mon Mar 01, 2004 12:09 pm
by ol4pr0
yep ;-)

sorry to not have mensioned it

Posted: Mon Mar 01, 2004 12:12 pm
by ol4pr0

Code: Select all

$links = array ("www.hammerslane.com","www.phpbuilder.com","www.linkynoworkyaaaaaaaaaa.com"); 

function chkuri($link) 
{ 
$churl = @fopen("http://".$link,'r');
shouldnt that be

Code: Select all

$churl = @fopen("http://.$link(+s),'r');
// or am i stupid here ?

Posted: Mon Mar 01, 2004 1:42 pm
by Steveo31
If anything

Code: Select all

PHP:

$churl = @fopen("http://.$link(+s),'r'"); 
// or am i stupid here ?
:P

Posted: Mon Mar 01, 2004 2:55 pm
by ol4pr0
?

Posted: Mon Mar 01, 2004 3:05 pm
by Illusionist
he added a quote that you left out, but i still think it should be this way:

Code: Select all

$churl = @fopen("http://.$link(+s)","r");
// or am i stupid here

Posted: Mon Mar 01, 2004 5:31 pm
by ol4pr0
ty for the confirmation of that ;-) and changing the other bits hehe

Posted: Tue Mar 02, 2004 4:24 am
by hammerslane
thanks for all the help guys! 8)