PHP 访问链接的3种方式

 对于php访问url的方法比价多,对于一些防护比较低的网站,可以轻易的实现刷网站浏览量的可能

1.fopen方式

function access_url($url) {    
    if ($url=='') return false;    
    $fp = fopen($url, 'r') or exit('Open url faild!');    
    if($fp){  
    while(!feof($fp)) {    
        $file.=fgets($fp)."";  
    }  
    fclose($fp);    
    }  
    return $file;  
}  

2.file_get_contents方式(打开远程文件的时候会造成CPU飙升。file_get_contents其实也可以post)

$content = file_get_contents("http://www.google.com");  

3.curl方式

function curl_file_get_contents($durl){  
    $ch = curl_init();  
    curl_setopt($ch, CURLOPT_URL, $durl);  
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true) ; // 获取数据返回    
    curl_setopt($ch, CURLOPT_BINARYTRANSFER, true) ; // 在启用 CURLOPT_RETURNTRANSFER 时候将获取数据返回    
    $r = curl_exec($ch);  
    curl_close($ch);  
    return $r;  
}  

如果需要不断访问某个链接,只需写一个for循环就好

for ($i=0; $i < 10 ; $i++) {
    //file_get_contents("http://www.speakphp.com/?post=98");
    //access_url("http://www.speakphp.com/?post=98");
    curl_file_get_contents("http://www.speakphp.com/?post=98");
    echo $i;
}
原文地址:https://www.cnblogs.com/xs-yqz/p/7601048.html