note 53498 deleted from function.fsockopen by betz

From: Date: Fri, 03 Jun 2005 14:40:56 +0000
Subject: note 53498 deleted from function.fsockopen by betz
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-89862@lists.php.net to get a copy of this message
Note Submitter: Anne ---- Ok, how would I use this script to test if a Teamspeak server is up? The TS server is on port 8767. So for example, how would I test to see if a port within an IP is functioning? The current script I have doesn't work. =( Can someone make any modifications that would get it to operate please? <?php /* *Configuration */ //What is the IP of the server we are testing? $serverIP = "1.1.1.1"; //What is the URL to the image we want to display if test passes? $passImgURL = "http://my.com/online.gif"; //What is the URL to the image we want to display if test fails? $failImgURL = "http://my.com/offline.gif"; /* *END Configuration */ $socket = fsockopen($serverIP, 8767, $errno, $errstr, 15); if ($socket) { fclose($socket); $imgToDisplay = $passImgURL; $imgAlt = "Server is Online"; } else { $imgToDisplay = $failImgURL; $imgAlt = "Server is Offline"; } ?> <img src="<?php echo $imgToDisplay; ?>" alt="<?php echo $imgAlt; ?>" /> <?php function checkURL($server, $port) { $ip = gethostbyname($server); $fp = fsockopen($ip, $port); if (!$fp) { ?> <img src="http://my.com/offline.gif" alt="Server is Offline"> <?php } else { ?> <img src="http://my.com/online.gif" alt="Server is Online"> <?php } } checkURL("1.1.1.1", "8767"); ?>

« previous php.notes (#89862) next »