| View previous topic :: View next topic |
| Author |
Message |
Localhost I post too much
Reputation: 0
Joined: 28 Apr 2007 Posts: 3402
|
Posted: Mon May 19, 2008 1:22 pm Post subject: [PHP] Pinging |
|
|
Hey, i want to make a script like
if ping www.website.com:8080 (true)
echo ¨IRC Server Up¨;
else ping www.website.com:8080 (false)
echo ¨IRC Server Down¨;
I know this wont work... Any other ways to check if a server is alive?
|
|
| Back to top |
|
 |
Reak I post too much
Reputation: 0
Joined: 15 May 2007 Posts: 3496
|
Posted: Mon May 19, 2008 2:05 pm Post subject: |
|
|
There is no ping function.
There is just some kind of connection function which will return false on timeout. There are alot scripts around
Example:
http://www.php-free.de/Detailed/1088.html
|
|
| Back to top |
|
 |
faenix Newbie cheater
Reputation: 0
Joined: 17 Sep 2007 Posts: 20
|
|
| Back to top |
|
 |
Noz3001 I'm a spammer
Reputation: 26
Joined: 29 May 2006 Posts: 6220 Location: /dev/null
|
Posted: Mon May 19, 2008 3:12 pm Post subject: |
|
|
| Code: | <?php
$status = fsockopen( "www.cheatengine.org", 80, 0, 0, 50 );
if ( !$status ) {
echo "Server down!\n";
} else {
echo "Server up!\n";
}
fclose( $status );
?> |
Something like that?
|
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8588 Location: 127.0.0.1
|
Posted: Mon May 19, 2008 7:51 pm Post subject: |
|
|
Avoiding the use of fsockopen, you can use normal sockets. I wrote this for my L2J server a while back to determine if the login server and game server were online. Heres a modded version for websites:
| Code: | <?php
$serverHost = "www.cheatengine.org";
$serverPort = 80;
function createSocket()
{
$socket = @socket_create( AF_INET, SOCK_STREAM, SOL_TCP );
@socket_set_option( $socket, SOL_SOCKET, SO_RCVTIMEO, array("sec"=>10, "usec"=>100) );
if( !$socket ){
die( 'Failed to create a new socket.' );
}else{
return $socket;
}
}
function CheckIfRunning()
{
global $serverHost, $serverPort;
$socket = createSocket();
$connection = @socket_connect( $socket, gethostbyname( $serverHost ), $serverPort );
if( !$connection )
echo( 'Server is not online.' );
else
echo( 'Server is online!' );
@socket_close( $socket );
}
?>
<HTML>
<HEAD>
<TITLE>Server Check</TITLE>
</HEAD>
<BODY>
<p> <?php CheckIfRunning(); ?> </p>
</BODY>
</HTML> |
_________________
- Retired. |
|
| Back to top |
|
 |
|