ianp Posted August 16, 2012 Share Posted August 16, 2012 I programmed a site for a friend and it worked fine the only problem is on the remote server it cant connect to the remote server. This is the script I am using class MCServerStatus { public $server; public $online, $motd, $online_players, $max_players; public $error = "OK"; function __construct($url, $port = '25565') { $this->server = array( "url" => $url, "port" => $port ); if ( $sock = @stream_socket_client('tcp://'.$url.':'.$port, $errno, $errstr, 1) ) { $this->online = true; fwrite($sock, "\xfe"); $h = fread($sock, 2048); $h = str_replace("\x00", '', $h); $h = substr($h, 2); $data = explode("\xa7", $h); unset($h); fclose($sock); if (sizeof($data) == 3) { $this->motd = $data[0]; $this->online_players = (int) $data[1]; $this->max_players = (int) $data[2]; } else { $this->error = "Cannot retrieve server info."; } } else { $this->online = false; $this->error = "Cannot connect to server."; } } } Link to comment https://forums.phpfreaks.com/topic/267198-cant-connect-to-server-on-remote-server-script-only-works-on-local-server/ Share on other sites More sharing options...
scootstah Posted August 16, 2012 Share Posted August 16, 2012 If it is a shared hosting server, the outgoing port is almost definitely going to be blocked. If it is a VPS/dedi you'll need to allow ports through the firewall. Link to comment https://forums.phpfreaks.com/topic/267198-cant-connect-to-server-on-remote-server-script-only-works-on-local-server/#findComment-1370028 Share on other sites More sharing options...
ianp Posted August 16, 2012 Author Share Posted August 16, 2012 Its a dedicated but I have the port unblocked. Link to comment https://forums.phpfreaks.com/topic/267198-cant-connect-to-server-on-remote-server-script-only-works-on-local-server/#findComment-1370035 Share on other sites More sharing options...
jazzman1 Posted August 17, 2012 Share Posted August 17, 2012 Do you have ssh access, if so can you connect through it ? Link to comment https://forums.phpfreaks.com/topic/267198-cant-connect-to-server-on-remote-server-script-only-works-on-local-server/#findComment-1370046 Share on other sites More sharing options...
scootstah Posted August 17, 2012 Share Posted August 17, 2012 What do you get by echo'ing $errstr and $errno? Also, you might try raising the timeout to 5 or 10 seconds. Link to comment https://forums.phpfreaks.com/topic/267198-cant-connect-to-server-on-remote-server-script-only-works-on-local-server/#findComment-1370048 Share on other sites More sharing options...
jazzman1 Posted August 17, 2012 Share Posted August 17, 2012 @scootstah, I had a dedicated server to godaddy, I've had to create a ssh tunnel to connect remotely to MySQL. Link to comment https://forums.phpfreaks.com/topic/267198-cant-connect-to-server-on-remote-server-script-only-works-on-local-server/#findComment-1370053 Share on other sites More sharing options...
scootstah Posted August 17, 2012 Share Posted August 17, 2012 @scootstah, I had a dedicated server to godaddy, I've had to create a ssh tunnel to connect remotely to MySQL. He's not connecting to MySQL, he appears to be connecting to a game server with a socket. As for you, you probably didn't have the MySQL config set properly. You have to explicitly allow remote connections. Link to comment https://forums.phpfreaks.com/topic/267198-cant-connect-to-server-on-remote-server-script-only-works-on-local-server/#findComment-1370056 Share on other sites More sharing options...
jazzman1 Posted August 17, 2012 Share Posted August 17, 2012 I've got it. Sorry for spamming Link to comment https://forums.phpfreaks.com/topic/267198-cant-connect-to-server-on-remote-server-script-only-works-on-local-server/#findComment-1370058 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.