关于测试curl 与file_get_contents抓取内容效率及稳定性
来源:互联网 发布:最新全国高校数据库 编辑:程序博客网 时间:2024/06/03 22:05
做过好多抓取别家网站内容的产品,从前,很习惯了使用方便快捷的file_get_contents函数,但是总是会遇到获取失败的问题,在本地测试有时候经常报错,很奇怪:
这时候,看一下服务器的连接池,会发现一堆类似的错误,让你头疼万分:
file_get_contents(http://***): failed to open stream…
不得已,安装了curl库,写了一个函数替换:01
function
curl_file_get_contents(
$durl
){
02
$ch
= curl_init();
03
curl_setopt(
$ch
, CURLOPT_URL,
$durl
);
04
curl_setopt(
$ch
, CURLOPT_TIMEOUT, 5);
05
curl_setopt(
$ch
, CURLOPT_USERAGENT, _USERAGENT_);
06
curl_setopt(
$ch
, CURLOPT_REFERER,_REFERER_);
07
curl_setopt(
$ch
, CURLOPT_RETURNTRANSFER, 1);
08
$r
= curl_exec(
$ch
);
09
curl_close(
$ch
);
10
return
$r
;
11
}
file_get_contents抓取google.com需用秒数:
2.31319094
2.30374217
2.21512604
3.30553889
2.30124092
curl使用的时间:
0.68719101
0.64675593
0.64326
0.81983113
0.63956594
差距很大吧?呵呵,从我使用的经验来说,这两个工具不只是速度有差异,稳定性也相差很大。建议对网络数据抓取稳定性要求比较高的朋友使用上面的curl_file_get_contents函数,不但稳定速度快,还能假冒浏览器欺骗目标地址哦!
0 0
- 关于测试curl 与file_get_contents抓取内容效率及稳定性
- file_get_contents与curl效率及稳定性问题
- 简评file_get_contents与curl 效率及稳定性
- 简评file_get_contents与curl 效率及稳定性
- 简评file_get_contents与curl 效率及稳定性
- 【转】file_get_contents与curl效率及稳定性问题
- php 简评file_get_contents与curl 效率及稳定性
- fsockopen/curl/file_get_contents效率比较
- 经典抓取网络数据方法效率分析(fsockopen/curl/file_get_contents)
- php file_get_contents抓取内容乱码
- php远程抓取函数curl(),file_get_contents
- file_get_contents与curl的比较
- curl与file_get_contents的比较
- file_get_contents与curl的比较
- 抓网页内容file_get_contents curl fopen
- file_get_contents函数抓取内容失败分析
- 抓取网页内容,用file_get_contents函数
- 用file_get_contents抓取远程网址内容
- PHP函数:CURL抓取网站内容的,支持301 302跳转
- android自动化测试报告调研
- 项目验收管理
- php使用curl存取cookie进行登录抓取数据示例
- Web内容管理系统 Magnolia
- 关于测试curl 与file_get_contents抓取内容效率及稳定性
- 教你如何将Access数据库移植到SQL Server
- jseclipse在eclipse中的安装
- php安全开发:添加随机字符串验证,防止伪造跨站请求
- WebPentester学习笔记
- C++ 学习笔记(一)
- 【转】Thread.sleep(0)的意义
- eclipse git window xp下 服务端搭建与使用(傻瓜教程 二)
- VideoUrlParser互联网视频地址分析工具,支持优酷、土豆等