Author Topic: Server Online Stats?  (Read 1019 times)

0 Members and 1 Guest are viewing this topic.

Offline Galaxyman

  • Major(1)
  • Posts: 14
Server Online Stats?
« on: January 15, 2009, 12:13:40 pm »
hey,
im searching for a script for my homepage, which shall do the following:
it shall check if my soldatserver is online, and if it is, it shall display the text "online" on my homepage. if the server is off, the text shal change into "offline". warlord made such a script once (stats.soldatnet) but this is not working anymore :(

well is there such a script or someone who can write this? :P

mfg Gala

Offline mar77a

  • Global Moderator
  • Veteran
  • *****
  • Posts: 1295
  • mad
    • random stuffs
Re: Server Online Stats?
« Reply #1 on: January 15, 2009, 12:34:36 pm »
Code: [Select]
<?php 

$ip 
'222.239.79.38';
$port 23073;

    
$start_time microtime(true);
    
$sock socket_create(AF_INET,SOCK_DGRAM,SOL_UDP);
    
socket_set_option($sockSOL_SOCKETSO_RCVTIMEO, array("sec" => 5"usec" => 1)); // 5 Second timeout
    
$packet 'i'.chr(0); // Ping packet from Client -> Server (Lobby ping)
    
socket_sendto($sock$packetstrlen($packet), 0x100$ip$port);
    do {@
socket_recvfrom($sock,$buffer,6,0,$ip,$port);} while(strlen($buffer) == 6);
    
$total_time round((microtime(true) - $start_time)*1000);
    
socket_close($sock);
     
    if (
$buffer == '') {
        echo 
"offline";
    }else{
        echo 
"online";
    }
?>


Offline Galaxyman

  • Major(1)
  • Posts: 14
Re: Server Online Stats?
« Reply #2 on: January 15, 2009, 12:41:15 pm »
oO nice, ill try it out, thanks!! ;)

//edit:

hm maybe im too stupid for this oO but how to put this into my html now? cause when i just copy the code, and print it into my html file, it doesnt work... ???

//edit2: when i upload the file and start it it says: Fatal error: Call to undefined function socket_create() in lol.php on line 7

//edit3: well now it just replies the whole code...oO
« Last Edit: January 15, 2009, 02:14:43 pm by Galaxyman »

Offline danmer

  • Camper
  • ***
  • Posts: 466
  • crabhead
Re: Server Online Stats?
« Reply #3 on: January 15, 2009, 03:46:38 pm »
make sure your file has the .php extension and that your host supports php properly

Offline Galaxyman

  • Major(1)
  • Posts: 14
Re: Server Online Stats?
« Reply #4 on: January 15, 2009, 04:34:50 pm »
i got apache to test the script out, and it says:

Fatal error: Call to undefined function: socket_create() in c:\apache\htdocs\dercode.php on line 7

Offline SpiltCoffee

  • Veteran
  • *****
  • Posts: 1579
  • Spilt, not Split!
    • SpiltCoffee's Site
Re: Server Online Stats?
« Reply #5 on: January 15, 2009, 07:20:21 pm »
It seems you have PHP on your web server. However, find out if your version of PHP is above 4.1.0.

Additionally, your host may have built PHP without the --enable-sockets command line switch, so that command might possibly just not work.
When life hands you High Fructose Corn Syrup, Citric Acid, Ascorbic Acid, Maltodextrin, Sodium Acid Pyrophosphate,
Magnesium Oxide, Calcium Fumarate, Yellow 5, Tocopherol and Less Than 2% Natural Flavour... make Lemonade!

Offline jrgp

  • Administrator
  • Flamebow Warrior
  • *****
  • Posts: 5037
Re: Server Online Stats?
« Reply #6 on: January 15, 2009, 11:02:07 pm »
Additionally, your host may have built PHP without the --enable-sockets command line switch, so that command might possibly just not work.
No, he's on windows. Apache is not built or compiled on Windows and hence the lack of that compilation switch. It is merely installed like any other windows app. His host needs to upgrade to the current version of php and make sure that sockets are allowed in the php.ini.
« Last Edit: January 15, 2009, 11:10:16 pm by jrgp »
There are other worlds than these

Offline Galaxyman

  • Major(1)
  • Posts: 14
Re: Server Online Stats?
« Reply #7 on: January 16, 2009, 08:36:41 am »
my php is version 4.1.1 :(

//edit: ok, i enabled something in php.ini oO now the script say:

Fatal error: Call to undefined function: socket_set_option() in c:\apache\htdocs\dercode.php on line 8

(next error lol)
what to do now? ???
« Last Edit: January 16, 2009, 08:51:21 am by Galaxyman »