Categories: PHP编程语言

使用curl替换file_get_contents的实现!

 

 

更新远程数据!

 

代码如下:

                    //$data1 = file_get_contents(‘http://bbs.chengdu.cn/i_index_newdata.php?fids=202,238,239,240,241,242,259,271’);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, ‘http://bbs.chengdu.cn/i_index_newdata.php?fids=202,238,239,240,241,242,259,271’);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 50);
$data1 = curl_exec($ch);
curl_close($ch);

由于是读取远程文件的内容,最终决定采用curl以替换file_get_contents,感觉速度与稳定性均有所上升,期间发生了点击更新按钮,无法更新的情况,最后通过 :curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 50);以解决此问题!

永夜