Heim  >  Artikel  >  Backend-Entwicklung  >  PHP中file_get_contents于curl性能效率比较_PHP教程

PHP中file_get_contents于curl性能效率比较_PHP教程

WBOY
WBOYOriginal
2016-07-13 10:22:401349Durchsuche

PHP中file_get_contents于curl性能效率比较

本篇文章分享一些在php中关于file_get_contents于curl性能效率的比较。文章内容整理自网络,如有不正确的地方,可及时留言补充纠正。

(1)fopen/file_get_contents 每次请求远程URL中的数据都会重新做DNS查询,并不对DNS信息进行缓存。但是CURL会自动对DNS信息进行缓存。对同一域名下的网页或者图片的请求只需要一次DNS 查询。这大大减少了DNS查询的次数。所以CURL的性能比fopen/file_get_contents 好很多。

(2)fopen/file_get_contents在请求HTTP时,使用的是http_fopen_wrapper,不会keeplive。而curl却可以。这样在多次请求多个链接时,curl效率会好一些。(设置header头应该可以)

(3)fopen/file_get_contents函数会受到php.ini文件中allow_url_open选项配置的影响。如果该配置关闭了,则该函数也就失效了。而curl不受该配置的影响。

(4)curl可以模拟多种请求,例如:POST数据,表单提交等,用户可以按照自己的需求来定制请求。而fopen/file_get_contents只能使用get方式获取数据。

(5)fopen/file_get_contents 不能正确下载二进制文件。

(6)fopen/file_get_contents 不能正确处理ssl请求。

(7)curl 可以利用多线程。

(8)使用 file_get_contents 的时候如果 网络出现问题, 很容易堆积一些进程在这里。

(9)如果是要打一个持续连接,多次请求多个页面。那么file_get_contents就会出问题。取得的内容也可能会不对。所以做一些类似采集工作的时候,用curl做替代是一个比较正确的选择。

您可能感兴趣的文章

  • 在php中分别使用curl的post提交数据的方法和get获取网页数据的方法总结
  • 用PHP函数memory_get_usage获取当前PHP内存消耗量以实现程序的性能优化
  • 该如何解决php运行出现Call to undefined function curl_init错误
  • php提示Call to undefined function curl_init() 错误的解决办法
  • PHP中return 和 exit 、break和contiue 区别与用法
  • php中$this、static、final、const、self 等几个关键字的用法
  • php利用filter函数验证邮箱、url和ip地址的方法
  • php生成短网址的思路以及实现方法

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/846810.htmlTechArticlePHP中file_get_contents于curl性能效率比较 本篇文章分享一些在php中关于file_get_contents于curl性能效率的比较。文章内容整理自网络,如有不正确的...
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn