FRIHOSTFORUMSSEARCHFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

Checking Server Status, Ping a Server (lots of purposes)

 


yimaw
Well, I came across this originally when I wanted to put a form on my website where a user could check the status of a counter-strike server.

What I found... Ping. Yes, you've probably used it. Ping at the command prompt in Windows or Unix checks server stats/connection speeds for you. Well, folks, its a PHP function too. There is one catch... You NEED root access if your host is running linux. Other than that, I don't think you should come across any problems. Ping looks like this

Code:
system("ping $host");



fairly simple. Now, if all you want to do is say, check on the status of localhost, you could just do...

Code:
$result = system("ping -c 1 localhost"); echo $result;



-c 1 ensures on linux machines that the ping command does not run continually, only once. You can change 1 to anything for the number of pings you want.

Now, I wanted to allow the user to check on the status of whatever server they wanted. So first I need to create a form.

Code:
<form action="suchandsuch.php" action="post">
Host:<input type="text" name="host">
<input type="submit">
</form>

Fairly simple form there . Anyway, now we need to process it in suchandsuch.php:

Code:
$host = $_POST['host'];

$data = system("ping -c 1 $host"); echo "$data";


And now you should have a form running that does what we want.
Related topics

Checking server status (ports) using PHP
Server status script
Frihost server status checker
Current server status
New Server Status page

How about adding server load to the server status script?
Server Status Page? Coming back anytime soon?
Is there new Server Status Gif
Server Status.
Server Status & Server 3

Server Status
Home Server Status Indicator
The root partition on this server is running out [SOLVED]
U3 Team
Checking The Web Site Speed
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.