PHP Ping Script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
hammerslane
Forum Newbie
Posts: 2
Joined: Mon Mar 01, 2004 7:07 am

PHP Ping Script

Post 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 :)
User avatar
AVATAr
Forum Regular
Posts: 524
Joined: Tue Jul 16, 2002 4:19 pm
Location: Uruguay -- Montevideo
Contact:

Post by AVATAr »

malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post 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
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post 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');
Roja
Tutorials Group
Posts: 2692
Joined: Sun Jan 04, 2004 10:30 pm

Post 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?
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post by ol4pr0 »

yep ;-)

sorry to not have mensioned it
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post 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 ?
Steveo31
Forum Contributor
Posts: 416
Joined: Sun Nov 23, 2003 9:05 pm
Location: San Jose CA

Post by Steveo31 »

If anything

Code: Select all

PHP:

$churl = @fopen("http://.$link(+s),'r'"); 
// or am i stupid here ?
:P
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post by ol4pr0 »

?
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post 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
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post by ol4pr0 »

ty for the confirmation of that ;-) and changing the other bits hehe
hammerslane
Forum Newbie
Posts: 2
Joined: Mon Mar 01, 2004 7:07 am

Post by hammerslane »

thanks for all the help guys! 8)
Post Reply