homepage Welcome to WebmasterWorld Guest from 54.234.141.47
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
fsockopen (timeout) question
firefly2442

10+ Year Member



 
Msg#: 1189 posted 3:30 am on Jun 23, 2003 (gmt 0)

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>

 

mavherick

10+ Year Member



 
Msg#: 1189 posted 4:50 am on Jun 23, 2003 (gmt 0)

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

firefly2442

10+ Year Member



 
Msg#: 1189 posted 3:40 pm on Jun 23, 2003 (gmt 0)

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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved