1

When I'm trying to use fsockopen I get operation timed out errcode 60 error.

This is failing within the recaptcha class, however it also occurs for the following snippet:

<?php
$fp = fsockopen("www.google.com", 80, $errno, $errstr, 30);
if (!$fp) {
    echo "$errstr ($errno)<br />\n";
} else {
    $out = "GET / HTTP/1.1\r\n";
    $out .= "Host: www.example.com\r\n";
    $out .= "Connection: Close\r\n\r\n";
    fwrite($fp, $out);
    while (!feof($fp)) {
        echo fgets($fp, 128);
    }
    fclose($fp);
}
?>

This error has started after I've switch my environment to use PHP 7.0.

The most interesting and funny thing is that it's working when I switch the URL to... www.stackoverflow.com getting HTTP/1.1 200 OK header.

Time out occurs for websites like: google.com, yahoo.com, facebook.com.

Base extensions are installed, including:

  • openssl,
  • sockets,
  • sessions

Exact PHP version:

# php -v
PHP 7.0.15 (cli) (built: Jan 24 2017 01:17:16) ( NTS 

Did any of you guys had similar issue and could point me in the right direction?

RA.
  • 969
  • 13
  • 36
  • May this helps: http://stackoverflow.com/questions/11682207/can-i-change-default-socket-timeout-from-my-php-code#11682254 – JustOnUnderMillions Jan 25 '17 at 14:49
  • @JustOnUnderMillions I've tried that, however page gets stuck, loading over and over again. – RA. Jan 25 '17 at 14:51
  • Sry can not help more, i was just pointing to your timeout issue. sockets are complex :-) – JustOnUnderMillions Jan 25 '17 at 14:55
  • Tip: `Time out occurs for websites like` google and other will block access when no real user is calling the page. bot/crawler prevention. – JustOnUnderMillions Jan 25 '17 at 14:56
  • @JustOnUnderMillions That wont make any sense if the same script works just fine under PHP 5.6. Not to even mention that the recaptcha class is using `www.google.com` URL for verifying originally. – RA. Jan 25 '17 at 15:03
  • `any sense` may the basic configuration in php.ini has changed or something internal in the socket function is now different. Check the PHP7 documentation for that. What was your old version? And check `google.com` in the browser, maybe you are currently blocked :) – JustOnUnderMillions Jan 25 '17 at 15:08

1 Answers1

0

Solved this issue myself.

It was caused by the firewall configration (using IPFW) script, for some reason it was refusing IPv6 connections, which wasn't happening before.

After allowing ip6 state connections, the problem is gone.

RA.
  • 969
  • 13
  • 36