Search code examples
phpsocketsconnection-timeout

fsockopen, can't get a foot in! Connection timeout


Excuse my terrible pun.

Basically, the deal is, the host is being a bitch. A simple fsockopen script, no matter what port, server, or anything, will connect. Trying to get server help from the webhost (due to unfortunate circumstances I have no way of changing hosts) proved ineffective... bunch of morons. A simple phpinfo() shows, however, that allow_url_fopen is on and Registered Stream Socket Transports allows me tcp, udp, unix, udg, ssl, sslv3, sslv2, tls.

So, what am I missing? Does it sound like the host is discreetly blocking socket connections? I mean, even port 80 doesn't work:

Warning: fsockopen() [function.fsockopen]: unable to connect to www.google.com:80 (Connection timed out)


Solution

  • Provided you are calling fsockopen correctly (you don't show code), that error is implying that yes, they are restricting you from making outbound connections.

    $fp = fsockopen("www.google.com", 80, $errno, $errstr, 30);
    if (!$fp) {
        echo "$errstr ($errno)<br />\n";
    }
    

    If you have shell access, try using telnet and you should see the same result:

    telnet www.google.com 80