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
fairly simple. Now, if all you want to do is say, check on the status of localhost, you could just do...
-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.
Fairly simple form there . Anyway, now we need to process it in suchandsuch.php:
And now you should have a form running that does what we want.
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.
