Welcome to WebmasterWorld Guest from 54.158.166.6

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

fsockopen (timeout) question

   
3:30 am on Jun 23, 2003 (gmt 0)

10+ Year Member



I have this piece of code that I made that displays information on game servers. It works fine when I run it on localhost (127.0.0.1), but when my friends try to access it, it times out and doesn't work. Any thoughts? Thanks.

PHP:--------------------------------------------------

<html>

<?php

include "./admin/config.inc.php";

mysql_connect($db_host,$db_user,$db_pass);
// login into the mysql database server

mysql_select_db($db_name);
// select the site's database

$query = mysql_query('SELECT * FROM games');
// get all the information in the 'ganes' table

while($games = mysql_fetch_array($query)) {

echo "<b>" . $games['Title'] . "</b>";
echo "<br>";
echo "<img src=" . "'" . $games['Picture'] . "'" . "border=0>";
echo "<br>";

//Turns off error reporting so that connection errors are ignored.
error_reporting(0);

$fp = fsockopen ($games['IP'], $games['Port'], $errno, $errstr, 2);
stream_set_timeout($fp, 1);

fclose($fp);

//Turns error reporting back on to default .ini value
error_reporting(E_ALL ^ E_NOTICE);

if ($fp == true) {
echo "<font color=green>";
echo "<b>" . "Server Up" . "</b>";
echo "</font>";
}
else {
echo "<font color=red>";
echo "<b>" . "Server Down" . "</b>";
echo "</font>";
}


echo "<br>";
echo $games['IP'] . ":" . $games['Port'];
echo "<br>";
echo "<a href=" . "'" . $games['Website'] . "'>" . $games['Website'] . "</a>";
echo "<br>";
if ($games['ModsRunning'] == 1) {
echo "This server is running the following mods-";
echo "<br>";
echo $games['Mods'];
}
else {
echo "This server is not running any mods.";
}

echo "<br>";
if ($games['MaxPlayers'] <> 0) {
echo "Max Players: " . $games['MaxPlayers'];
}
else {
echo "Max Players: " . "Unknown";
}
echo "<br>";
echo $games['ExtraInfo'];

echo "<hr>";
}

?>

</html>

4:50 am on Jun 23, 2003 (gmt 0)

10+ Year Member



This code stream_set_timeout($fp, 1); tells your script to try to establish a connection in under a second, you might want to increase the timeout a little and see if it works.

mavherick

3:40 pm on Jun 23, 2003 (gmt 0)

10+ Year Member



Thanks. That worked great. I have another question though. For some servers it must be trying to open a socket connection and get data or something. All I need to do is see if the IP and Port is valid and open. Most game servers work but the new ones don't seem to be working. Any thoughts? Thanks.