DEV Community

Debajyoti Das
Debajyoti Das

Posted on

fsocket open php/laravel

To check if server can be connected to:

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

        dump($a);
Enter fullscreen mode Exit fullscreen mode

Op if success:

Image description

Top comments (0)