I am just looking to tidy the output form

echo '<body bgcolor="#FFFFFF" text="#000000"></body>';
echo("Ping Output:<br>");
echo "<pre>";
$i = "11";

//check target IP or domain
system("ping -n 1 192.168.2.$i");
echo "</pre>";

I am just looking for somthing like this
Reply from 192.168.2.11: bytes=32 time<10ms TTL=128

With nothing else.

Why not do something like this?

<?php
$string = 'REPLY FROM'; // your ping output data
if (eregi('REPLY FROM', $string)) {
   echo "'$string' Host is up!";
}
?>

Just seems better then echoing out all the data.... Just my .02

Because this can not be copied into a string, or can you?

//check target IP or domain
$string = system("ping -n 1 192.168.2.11"); // your ping output data

echo "$string";

if (eregi('REPLY FROM', $string))
{
echo "'$string' Host is up!";
}
echo "</pre>";

Just out put that to a FILE. then read in from the file

like

somecommand > somefile.txt

then

<?php
$hi = file("somefile.txt");
$string=print_r($hi);
?>

follow?

Got it but just one problem i get an error if it exceeds 30 seconds


Fatal error: Maximum execution time of 30 seconds exceeded in C:\Apache\Apache2\htdocs\ping\pingshort.php on line 12

// over count ?
   echo '<body bgcolor="#FFFFFF" text="#000000"></body>';
   echo("Ping Output:<br><br>"); 
//   echo "<pre>";  

   //check target IP or domain

for ($i = 10; $i <= 60; $i++)
{
	$string[$i] = shell_exec("ping -n 1 192.168.2.$i"); // your ping output data

	//echo "<br><b>$string[$i]</b><br>";

	if (eregi('Received = 1', $string[$i]))
	{
	   echo "<b>Host 192.168.2.$i is up!</b><br>";
	}

		else 
		{
			echo "Host  192.168.2.$i is down<br>";
		}

}

That is a php.ini setting

So you have two choices...

One increase the execution time.. or two... set a counter in there to count to 10.. if you reach 10 before output conside rthe host down or say timeout or something
but just break out of the program.

That is a php.ini setting

So you have two choices...

One increase the execution time.. or two... set a counter in there to count to 10.. if you reach 10 before output conside rthe host down or say timeout or something
but just break out of the program.

I would start by lengthening the execution time, only because it may be taking time to ping the host. write to file, then read the file. If lets say you extend the time to sixty seconds, and it still fails out because its still running the execution, then you may need to put in a break, or try pining somthing other than the entered IP to make sure that your script is working.


Try pinging somthing like www.google.com or ping the loopback address 127.0.0.1 If you still run into execution time errors for known working pings then it somthing in the script.

but certainly its a great idea to input a break after x ammount of time, because if you have to wait longer than thirty seconds to simply do a ping of a host and see if its good; you're better of opening up the DOS prompt and typing ping "xxx.xxx.xxx.xxx" (where xxx is the corresponding IP)

If you cannot alter php.ini try this on the top of your code:

set_time_limit(120);

That will do the job hust for the execution of that script.

You can use set_time_limit(0); also so the script will not time out until it finishes running but I do not recommend this.

the php_ini set flag is a good idea before adjusting the execution time for every script on the box.

But you should honestly be able to handle this in the code it self without having to even change a flag.

Not sure how many hosts you are checking but with a single ping on say 10 down machines should not take longer then 10 seconds to run.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.