CodeIgniter Forums
fsockopen(): unable to connect to remote server ip - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Development (https://forum.codeigniter.com/forumdisplay.php?fid=6)
+--- Forum: CodeIgniter 3.x (https://forum.codeigniter.com/forumdisplay.php?fid=17)
+--- Thread: fsockopen(): unable to connect to remote server ip (/showthread.php?tid=78605)



fsockopen(): unable to connect to remote server ip - waraywarayako - 02-13-2021

Good Day,

I am working with Online Games Frontend Template. werein I am fetching data from GAMES REMOTE server. I am able to connect to the remote server MSSQL Database but the fsockopen() does not work and I already allowed the Web Hosting IP to our Server Inbound connection. Please see codes below


PHP Code:
function getServerConnection($ip$port) {
        
$sockres = @fsockopen($ip$port$errno$errstr0.01);
        if (!
$sockres) {
            return 
'<b class="text-danger">OFFLINE</b>';
        } else {
            @
fclose($sockres);
            return 
'<b class="text-success">ONLINE</b>';
        }
    } 

when I var_dump the ($sockres) this was the result
Quote:A PHP Error was encountered
Severity: Warning
Message: fsockopen(): unable to connect to 192.168.1.1:80 (Connection timed out) - JUST DUMMY IP. IT HAS A REAL REMOTE IP
Filename: helpers/myhelper_helper.php

bool(false) int(110) string(20) "Connection timed out"

I`ve search a lot on the internet but we have different error, their is for send Emails while mine is only to check if the Server is ONLINE or OFFLINE

NOTE: This is working on a local PC, but if it for my webhosting to remote game server it won`t work except for fetching data from remote server MSSQL database.


RE: fsockopen(): unable to connect to remote server ip - gosocial2 - 02-14-2021

In your php.ini, is allow_url_fopen = On ?


RE: fsockopen(): unable to connect to remote server ip - waraywarayako - 02-14-2021

allow_url_fopen was already enabled.


RE: fsockopen(): unable to connect to remote server ip - Avrora - 02-23-2021

(02-13-2021, 02:24 PM)waraywarayako Wrote: Good Day,

I am working with Online Games Frontend Template. werein I am fetching data from GAMES REMOTE server. I am able to connect to the remote server MSSQL Database but the fsockopen() does not work and I already allowed the Web Hosting IP to our Server Inbound connection. Please see codes below


PHP Code:
function getServerConnection($ip$port) {
        
$sockres = @fsockopen($ip$port$errno$errstr0.01);
        if (!
$sockres) {
            return 
'<b class="text-danger">OFFLINE</b>';
        } else {
            @
fclose($sockres);
            return 
'<b class="text-success">ONLINE</b>';
        }
    } 

when I var_dump the ($sockres) this was the result
Quote:A PHP Error was encountered
Severity: Warning
Message: fsockopen(): unable to connect to 192.168.1.1:80 (Connection timed out) - JUST DUMMY IP. IT HAS A REAL REMOTE IP
Filename: helpers/myhelper_helper.php

bool(false) int(110) string(20) "Connection timed out"

I`ve search a lot on the internet but we have different error, their is for send Emails while mine is only to check if the Server is ONLINE or OFFLINE

NOTE: This is working on a local PC, but if it for my webhosting to remote game server it won`t work except for fetching data from remote server MSSQL database.
An incomprehensible situation, it is interesting to know the solution to the problem.


RE: fsockopen(): unable to connect to remote server ip - paliz - 02-23-2021

Use pusher service
I tested work very wellllllll
https://pusher.com/


RE: fsockopen(): unable to connect to remote server ip - HenryChapman - 11-12-2023

I have a similar problem, and I haven't found a solution yet. You can try checking if the firewall on the remote game server allows incoming connections on the specified port (in this case, port 80). Also, check for any security groups or access control lists (ACLs) that might be blocking the connection. Also, make sure that the $ip parameter in your fsockopen function contains the correct IP address or hostname of the remote game server. If it's a hostname, ensure that DNS resolution is working correctly on your web hosting server.