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

查看:183
本文介绍了使用文件获取内容或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?

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.

推荐答案

在我运行api之前,我需要一整天的时间来处理。几年前我基准测试了这两个和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天全站免登陆