Server status

01/08/2014 21:22 LordGragen.#1
I am learning php so i dont know much yet but this question might be easy for you guys.


Code:
if (!$socket = @fsockopen("25.206.182.32", 5816, $errno, $errstr, 30))
{
  echo "<font color='red'><strong>Offline!</strong></font>";
}
else 
{
  echo "<font color='green'><strong>Online!/strong></font>";
  

  fclose($socket);
}
is this rly bad way show the server status?

i tried with my localhost (127.0.0.1) (80) it was working fast

but when i tried with the hamachi ip and the port it was taking so long and then not even loading the whole website.

any suggestion how i should control the status?
01/09/2014 00:25 Spirited#2
TQ has it so the php website cycles through the servers every once and a while and changes a simple text file. Then, requests to see if the server is online or not goes through that file, instead of pinging each server repetitively for each person accessing the website. The file used to be located at the root of their website, "status.php". It was changed to "server.co.91.com" which now returns "Bad Gateway".

Quoting myself from the CO2 Underground (since it is my own released information), here's the structure of TQ's old file that the old clients use in their server checks:
Quote:
The Conquer Online client has a server status check in the login screen next to the selected server. You can change the check to show the status of your server by opening "common.ini" and changing ServerStatus. The php file being read is composed as text. There are no html or xml elements. Each line contains the server name and the server status. The server name is a string. The server status is represented as an unsigned integer (ranging from 0 to 3). 0 is "Down", 1 is "Overloaded", 2 is "Busy", and 3 is "Online".
01/13/2014 02:03 Y u k i#3
Also, you could do it with jscript async, so it wont block the loading of your site. Plus a timeout of lets say 200ms should be sufficient for a ping packet..
01/13/2014 03:11 Super Aids#4
You really shouldn't open a connection to the server from the website at anytime.

If anything have it either updating a textfile and if the file wasn't modified within a specific timespan eg. 15 seconds then the server is offline.

Or do the same princip but using a database ex. MySQL, MSSQL etc.

It will leave connection overloads out for the server.

Quote:
Originally Posted by Y u k i View Post
Also, you could do it with jscript async, so it wont block the loading of your site. Plus a timeout of lets say 200ms should be sufficient for a ping packet..
I know it probably wouldn't be a problem with a pserver, but let's say he has a traffic of 1000 people at on his website and it keeps pinging every 200 ms.

That would be 5000 connections done every second to the server and not even a legit logged in client.
01/13/2014 07:42 KraHen#5
Or just set up a client socket in the server itself and send an "I`m alive" packet to your PHP or Node.js or whatever server.