Portal Home > Knowledgebase > Articles Database > [PHP] fsockopen() & Connection refused (111)


[PHP] fsockopen() & Connection refused (111)




Posted by Onture, 12-01-2006, 05:01 AM
I'm having problems using fsockopen() to connect to a local web server. I have set up port forwarding and everything already. If I manually type the address in my web browser it works. But through php's fsockopen() it does not connect. Heres a sample code: I get; Warning: fsockopen(): unable to connect to xxx.xxx.xxx.xxx:8888 in /home/blah/www/scripts/test.php on line 5 Connection refused (111) But when I access it internally via browser manually; ie: http://192.168.0.1:8888/scripts/test.php it works fine?! I tried accessing it from an external computer [with external IP]; http://xxx.xxx.xxx.xxx:8888/scripts/test.php and it works fine as well. The only thing I can think of is fsockopen doesn't like accessing resource if its a port forwarded resource by the router? I tried two different routers with port forwarding. Any other solutions greatly appreciated.

Posted by RayonMazter, 12-01-2006, 06:01 PM
Is the webhost being run off the same computer you are trying to access it with? 192.*.*.* ip addresses are 'private' router ip's. They are not public. get your real ip from whatsmyip.org and try that in the script. And if your already using your public ip, attempt using the IP given by the router. Sorry if this is not helpful and I understood you incorrectly. Ray

Posted by Onture, 12-02-2006, 11:51 AM
Yeah its not an internal IP. I have it set up where I can access it via internal IP or external IP hence the port forwarding.

Posted by localhost127, 12-02-2006, 12:57 PM
Is the server running this malfunctioning PHP script located on your network? If so, with most routers you will have to use the internal IP instead of the external for any machines on the same network.

Posted by Onture, 12-02-2006, 11:35 PM
This is how its currently set up: WEBHOST -> INTERNET -> ADSL Router [Port Forward 8888 Apache] -> Local Lan -> Local Workstation [Apache port 8888] WEBHOST contains a script where the visitor signs up for a account. This script checks whether the visitors phone number exist or not. The database it queries to check this is on a local server which is a MYOB Premier with ODBC+PHP [check.php?phone=blah]. This returns a result whether it exists or not. I can access this script manually with http://real-ip:8888/check.php?phone=blah and it works fine. But using that in the PHP script with fsockopen() does not work and I get a Warning: fsockopen(): unable to connect to xxx.xxx.xxx.xxx:8888 in /home/blah/www/scripts/check.php on line 5 Connection refused (111) error. Very weirrrrrrrdddddddddd :O

Posted by localhost127, 12-03-2006, 12:43 AM
It is possible your web host is firewalling your external connections. Perhaps try connecting to google on port 80 or something just to verify that is not the issue.

Posted by Burhan, 12-03-2006, 04:01 AM
It might be that your webhost has restricted ports being opened by the Apache process, a lot do this to prevent spamming.

Posted by Onture, 12-03-2006, 04:46 AM
If I specify another website like Google and others, it will work. I'll try port triggering instead of port forwarding in my adsl router when I return to work tomorrow.

Posted by Onture, 12-03-2006, 11:18 PM
It ended up to be my ISP which blocked the common ports 80/443. I had to toggle it off in the control panel. The error still occured if I used a different port. So I guess Apache will only work with 80 which is the way the ISP configured PHP/Apache.

Posted by Ks Jeppe, 12-04-2006, 05:41 PM
Just a thought, but you sure that you should be sending Host: in the header? I don't remember 100% correct, but i think i had the same problem, working off ip's and sending host in the header...

Posted by seekndestroy88, 06-30-2010, 03:50 AM
onture How you managed to solve this issue then ? Please share here. i am also facing the same issue while using ozeki sms server

Posted by Korvan, 06-30-2010, 01:07 PM
Try using curl instead of fsock to open the web page and see if that makes any difference.

Posted by jmunki, 06-30-2010, 01:38 PM
i maybe way off base, but if your trying to redirect; header("Location: http://domain.com/blah/di/blah.php"); or the thing i tend to use to run remote scripts is: $webby = "http://domain.com/blah/blah/blah"; $result = file_get_contents($webby); $xyz = $result; if $xyz.... etc

Posted by mattle, 06-30-2010, 03:01 PM
What happens if you try: from the same machine that's executing the php script? Let's try to isolate whether this is a networking issue, or an issue with fsockopen()...



Was this answer helpful?

Add to Favourites Add to Favourites    Print this Article Print this Article

Also Read
rsync (Views: 468)
VShost vs Sultanhost (Views: 471)