FSocket开放php/laravel
#php #laravel #socket

检查服务器是否可以连接到:

$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);

op如果成功:

Image description