php 调用远程url

// ; Whether to allow the treatment of URLs (like http:// or ftp://) as files.
// ; http://php.net/allow-url-fopen
// allow_url_fopen = On
//前三个都需要开启 allow_url_fopen
//1、file_get_contents()///////////////////////
$file = file_get_contents("http://www.baidu.com");
//2、fopen()///////////////////
$file2 = fopen("http://www.baidu.com","r");
while(!feof($file2)){
        $file2_content .= fgets($file2);    
}
//3、file()////////////////////////////////////////////
$file3 = file("http://www.baidu.com");
//4、fsockopen()//////////////////////////////////////////
//print_r(stream_get_transports());//获取已注册的套接字传输协议列表
$fp = fsockopen("www.cnblogs.com", 80, $errno, $errstr, 30); 
if (!$fp) { 
    echo "$errstr ($errno) "; 
} else { 
   $out = "GET / HTTP/1.1
";
   $out .= "Host: www.cnblogs.com.com
";
   $out .= "Connection: Close

";
    fwrite($fp, $out); 
    while (!feof($fp)) { 
     echo fgets($fp, 128); 
    } 
    fclose($fp); 
}
原文地址:https://www.cnblogs.com/natian-ws/p/6708832.html