Using the System() function to run a ping

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
impulse()
Forum Regular
Posts: 748
Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:

Using the System() function to run a ping

Post by impulse() »

I stumbled across a script that lets you input a host to ping and it shows the results on the screen. This particular script returns each ping when it has results for it though, so a ping count of 10 will return each ping as it is detected.
I tried to write my own script to do exactly the same, but mine only returns the data once it has completed the process. So if I run a count of 10 pings then the webpage hangs untill the process is complete.
Could someone point out what I need to do for the script to return each ping result when it's returned in the shell. I'm running on a Linux box you may want to know.

Here is my code:

Code: Select all

$host = $_POST["host"];
$count = $_POST["count"];

system("ping $host -c $count");

Regards,
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Post Reply