Author Topic: How to make script to check status?  (Read 3388 times)

0 Members and 1 Guest are viewing this topic.

Offline nut29951

  • Major(1)
  • Posts: 4
How to make script to check status?
« on: September 22, 2006, 11:09:53 pm »
I have my own website and i use my PC to dedicated server
how to make a script that check my server status that online or offline

Option that i have ???
-My PC is not my website server(I use web hosting)
-PHP or html script
-My internet is ADSL (ip change every time i connect)

Sorry for my bad english

Offline EnEsCe

  • Retired Soldat Developer
  • Flamebow Warrior
  • ******
  • Posts: 3101
  • http://enesce.com/
    • [eC] Official Website
Re: How to make script to check status?
« Reply #1 on: September 23, 2006, 12:19:37 am »
<?php
$serverip = '127.0.0.1';
$port = 23073;
if(fsockopen($serverip,$serverport,$errstr,$errnum,5)) $status='Online'; else $status='Offline';
echo $status;
?>

Simple. Thats just off the top of my head.

Offline nut29951

  • Major(1)
  • Posts: 4
Re: How to make script to check status?
« Reply #2 on: September 23, 2006, 07:35:18 am »
And what about IP that change every time i connect internet?
i have one idea but i don't know how to do it
such as check server name from lobby ???

Offline ramirez

  • Retired Soldat Developer
  • Camper
  • ******
  • Posts: 394
    • Soldat Central
Re: How to make script to check status?
« Reply #3 on: September 26, 2006, 08:14:36 am »
If you have a dynamic DNS for your IP, you can connect to the hostname instead of your IP, so it will resolve to the correct IP.
It should be a better way around it than get the IP from lobby, because it doesn't rely that the lobby is up and if you decided to hide the server from lobby, it wouldn't break.

If you don't have a dynamic DNS for your IP, google for them, as far as I know there should be plenty of free providers.

Also, you might want to prefix fsockopen with @, and use @fsockopen to suppress a warning message PHP generates if the error reporting level is high. Also, if the script runs on the same server as the soldat server (as in EnEsCe's script), you can just use 127.0.0.1.

Offline nut29951

  • Major(1)
  • Posts: 4
Re: How to make script to check status?
« Reply #4 on: September 27, 2006, 09:53:00 am »
<?php
$serverip = '127.0.0.1';
$port = 23073;
if(fsockopen($serverip,$serverport,$errstr,$errnum,5)) $status='Online'; else $status='Offline';
echo $status;
?>

Simple. Thats just off the top of my head.

Can i use no-ip.com for  Dynamic DNS and change $serverip to 'xxxx.no-ip.org' ?

And what is $errstr and $errnum

Thank you for your answer
« Last Edit: September 27, 2006, 09:55:43 am by nut29951 »

Offline EnEsCe

  • Retired Soldat Developer
  • Flamebow Warrior
  • ******
  • Posts: 3101
  • http://enesce.com/
    • [eC] Official Website
Re: How to make script to check status?
« Reply #5 on: September 27, 2006, 05:46:55 pm »
Yes you can use the the dynamic DNS as $serverip

And in the event of an error, the $errstr variable will contain the error string and $errnum will be the error number. The 5 is the timeout in seconds.

Offline nut29951

  • Major(1)
  • Posts: 4
Re: How to make script to check status?
« Reply #6 on: September 28, 2006, 04:03:57 am »
<?php
$serverip = 'nut29951.no-ip.org';
$port = 23073;
if(fsockopen($serverip,$serverport,$errstr,$errnum,5)) $status='Online'; else $status='Offline';
echo $status;
?>

is this code correct?
It always show offline

Offline mikembm

  • Soldier
  • **
  • Posts: 210
Re: How to make script to check status?
« Reply #7 on: October 06, 2006, 02:30:13 pm »
Yeah, I tried this script and I cant get it to work using my own webserver.
The game server and web server are both run from my own computer

However, on my freely-hosted webserver, it works just fine.

Offline mar77a

  • Global Moderator
  • Veteran
  • *****
  • Posts: 1295
  • mad
    • random stuffs
Re: How to make script to check status?
« Reply #8 on: October 06, 2006, 04:15:25 pm »
If you are hosting on the same computer, you can check the modification time of gamestat.txt.

Offline mikembm

  • Soldier
  • **
  • Posts: 210
Re: How to make script to check status?
« Reply #9 on: October 08, 2006, 09:00:47 am »
What about a script like:

if($sh = fsockopen($server_ip, $server_port, $errno, $errstr, 5)) {
fwrite($sh,"$adminlog_pass\n");
fwrite($sh,"/say test\n");
fclose($sh);

This works on other hosted webservers but on my own it does not.
For some reason the fsockopen doesnt connect to a localhost server...