Krisando Posted July 6, 2009 Share Posted July 6, 2009 Hello, I'm trying to get a little piece of code working here. What it does is connect to a program on a certain port "7171", that is the problem. It wont seem to initilize the connection. Code: $sock = @fsockopen("118.90.70.75", 7171, $errno, $errstr, 1); if ($sock) { fwrite($sock, $info); $data=''; while (!feof($sock)) $data .= fgets($sock, 1024); fclose($sock); preg_match('/players online="(\d+)" max="(\d+)"/', $data, $matches); $config['status']['serverStatus_online'] = 1; $config['status']['serverStatus_players'] = $matches[1]; $config['status']['serverStatus_playersMax'] = $matches[2]; preg_match('/uptime="(\d+)"/', $data, $matches); $h = floor($matches[1] / 3600); $m = floor(($matches[1] - $h*3600) / 60); $config['status']['serverStatus_uptime'] = $h.'h '.$m.'m'; preg_match('/monsters total="(\d+)"/', $data, $matches); $config['status']['serverStatus_monsters'] = $matches[1]; } else { $config['status']['serverStatus_online'] = 0; $config['status']['serverStatus_players'] = 0; $config['status']['serverStatus_playersMax'] = 0; } I'm not sure what "$errno, $errstr" means. Maybe this could help me or be my problem? Link to comment https://forums.phpfreaks.com/topic/164899-fsockopen-not-opening-socket-or-atleast-correctly/ Share on other sites More sharing options...
seventheyejosh Posted July 6, 2009 Share Posted July 6, 2009 http://us3.php.net/manual/en/function.fsockopen.php Link to comment https://forums.phpfreaks.com/topic/164899-fsockopen-not-opening-socket-or-atleast-correctly/#findComment-869554 Share on other sites More sharing options...
Krisando Posted July 6, 2009 Author Share Posted July 6, 2009 Yes that was esactly what I needed. Trying tcp since its accessing a remote server: "$sock = @fsockopen("tls://fsf.servegame.com", 7171, $errno, $errstr, 1);" I think thats right syntax still not working, hmm. Link to comment https://forums.phpfreaks.com/topic/164899-fsockopen-not-opening-socket-or-atleast-correctly/#findComment-869580 Share on other sites More sharing options...
Tonic-_- Posted July 6, 2009 Share Posted July 6, 2009 if (! $sock = @fsockopen("118.90.70.75", "7171", $num, $error, 5)) { fwrite($sock, $info); $data=''; while (!feof($sock)) $data .= fgets($sock, 1024); fclose($sock); preg_match('/players online="(\d+)" max="(\d+)"/', $data, $matches); $config['status']['serverStatus_online'] = 1; $config['status']['serverStatus_players'] = $matches[1]; $config['status']['serverStatus_playersMax'] = $matches[2]; preg_match('/uptime="(\d+)"/', $data, $matches); $h = floor($matches[1] / 3600); $m = floor(($matches[1] - $h*3600) / 60); $config['status']['serverStatus_uptime'] = $h.'h '.$m.'m'; preg_match('/monsters total="(\d+)"/', $data, $matches); $config['status']['serverStatus_monsters'] = $matches[1]; } else { $config['status']['serverStatus_online'] = 0; $config['status']['serverStatus_players'] = 0; $config['status']['serverStatus_playersMax'] = 0; fclose($sock); } That should work for you. Link to comment https://forums.phpfreaks.com/topic/164899-fsockopen-not-opening-socket-or-atleast-correctly/#findComment-869634 Share on other sites More sharing options...
Tonic-_- Posted July 6, 2009 Share Posted July 6, 2009 Opps sorry brain fart, had two minor erros. if ( $sock = @fsockopen("118.90.70.75", "7171", $num, $error, 5)) { fwrite($sock, $info); $data=''; while (!feof($sock)) $data .= fgets($sock, 1024); fclose($sock); preg_match('/players online="(\d+)" max="(\d+)"/', $data, $matches); $config['status']['serverStatus_online'] = 1; $config['status']['serverStatus_players'] = $matches[1]; $config['status']['serverStatus_playersMax'] = $matches[2]; preg_match('/uptime="(\d+)"/', $data, $matches); $h = floor($matches[1] / 3600); $m = floor(($matches[1] - $h*3600) / 60); $config['status']['serverStatus_uptime'] = $h.'h '.$m.'m'; preg_match('/monsters total="(\d+)"/', $data, $matches); $config['status']['serverStatus_monsters'] = $matches[1]; fclose($sock); } else { $config['status']['serverStatus_online'] = 0; $config['status']['serverStatus_players'] = 0; $config['status']['serverStatus_playersMax'] = 0; } Link to comment https://forums.phpfreaks.com/topic/164899-fsockopen-not-opening-socket-or-atleast-correctly/#findComment-869636 Share on other sites More sharing options...
Krisando Posted July 7, 2009 Author Share Posted July 7, 2009 The last "fclose($sock);" errored it I think because it was tryign to close the socket after it had already been closed so I took that off and it seems to be doing exactly the same thing. It works fine locally/on my webserver accessed by someone else but not on my domains webserver, so it's a very strange problem indeed. Link to comment https://forums.phpfreaks.com/topic/164899-fsockopen-not-opening-socket-or-atleast-correctly/#findComment-870146 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.