使用文件获取内容或 curl [英] using file get contents or curl

查看:59
本文介绍了使用文件获取内容或 curl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我被要求使用一个简单的 facebook api 来返回工作中喜欢或分享的数量,这些数量会返回 json 字符串.现在,由于我要为大量链接执行此操作,因此哪个更好:

I was ask to use a simple facebook api to return the number of likes or shares at work which return json string. Now since i am going to do this for a very large amount of links, which one is better:

使用 file_get_contents 或 cURL.

Using file_get_contents or cURL.

两者似乎都返回相同的结果,cURL使用起来似乎更复杂,但它们之间有什么区别.为什么大多数人建议在 file_get_contents 上使用 cURL?在我运行可能需要一整天才能处理的 api 之前,我希望得到反馈.

Both of them seem to return the same results and cURL seems to be more complicated to use, but what is the difference among them. why do most people recommend using cURL over file_get_contents? Before i run the api which might take a whole day to process, i will like to have feedback.

推荐答案

几年前,我对两者进行了基准测试,CURL 速度更快.使用 CURL,您可以创建一个可用于每个请求的 CURL 实例,它直接映射到速度非常快的 libcurl 库.使用 file_get_contents 会产生协议包装器的开销以及为每个请求执行的初始化代码.

A few years ago I benchmarked the two and CURL was faster. With CURL you create one CURL instance which can be used for every request, and it maps directly to the very fast libcurl library. Using file_get_contents you have the overhead of protocol wrappers and the initialization code getting executed for every single request.

我将挖掘我的基准脚本并在 PHP 5.3 上运行,但我怀疑 CURL 仍然会更快.

I will dig out my benchmark script and run on PHP 5.3 but I suspect that CURL will still be faster.

这篇关于使用文件获取内容或 curl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆