note 53498 added to function.fsockopen

From: Date: Fri, 03 Jun 2005 14:19:11 +0000
Subject: note 53498 added to function.fsockopen
Groups: php.notes 
Request: Send a blank email to php-notes+get-89859@lists.php.net to get a copy of this message
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"); ?> ---- Manual Page -- http://www.php.net/manual/en/function.fsockopen.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+53498 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+53498&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+53498&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+53498&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+53498&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+53498&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+53498&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#89859) next »