Ping through PHP

nunoabc

New Member
Messages
151
Reaction score
0
Points
0
Hello everybody!

I want a script that pings (only once) my game server through PHP and it shows a green light image if it is online and a red light image if it is offline. The script needs to be functional.
I Googled a lot, found some pages that told me to do this and that but when I tried them they didn't work.

IP: 77.91.203.194
Port: 27019
Game: Counter-Strike 1.6

I need to know what PHP version I need in x10Hosting. If you need more information, let me know.
 
Last edited:

Adam01

New Member
Messages
114
Reaction score
0
Points
0
uhhh, I've fought about something like this, but my idea would check my database connection.
And I have no idea how to ping a server.
 

cetutnx1

New Member
Messages
510
Reaction score
0
Points
0
@sunils: i get a 404 when i try to fetch the file...

acctually is very easy...

it's done via fsockopen function

Example:
Code:
function usage : resource fsockopen  ( string $nombre_host  [, int $puerto  [, int &$errno  [, string &$errstr  [, float $tiempo_espera  ]]]] )

//this function that i've found on php comments is very good and very easy

// check if a server is up by connecting to a port
function chkServer($host, $port)
{  
    $hostip = @gethostbyname($host); // resloves IP from Hostname returns hostname on failure
   
    if ($hostip == $host) // if the IP is not resloved
    {
        echo "Server is down or does not exist";
    }
    else
    {
        if (!$x = @fsockopen($hostip, $port, $errno, $errstr, 5)) // attempt to connect
        {
            echo "Server is down";
        }
        else
        {
            echo "Server is up";
            if ($x)
            {
                @fclose($x); //close connection (i dont know if this is needed or not).
            }
        } 
    }
}

//and the usage will be
chkServer ('www.hostname.com','portNumber');

//The the output will be
echo Server Up o Server down...
 
Last edited:

sunils

New Member
Messages
2,266
Reaction score
0
Points
0
Sorry about the error,

i thought of uploading the content once the coding was finished.

But i could not access the control panel to upload it.

Since the coding is done i think no need to post the code again.

Any thnx for this coding...............
 
Top