【问题标题】:Fastest method of xml or json HTTP request? [duplicate]xml或json HTTP请求的最快方法? [复制]
【发布时间】:2015-01-19 03:42:00
【问题描述】:

我注意到 curl 比 file_get_contents 快很多,还有什么更快的吗?

$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL,'http://api.blah.com/xml.php');
$content = curl_exec($ch);
$xml = new SimpleXMLElement($content);

$file = file_get_contents('http://api.blah.com/xml.php');
$xml = new SimpleXMLElement($file);

现在还有很多其他类似的问题,但没有一个能回答主要问题,是否有更快的测试替代方案?没有其他人提供此答案,有些人提到了套接字,但没有人提供比较测试速度。

【问题讨论】:

  • 如果 curl 比 file_get_contents 快很多,你应该检查你的服务器配置,因为通常情况下不应该这样。

标签: php xml curl file-get-contents


【解决方案1】:

现在file_get_contents 很快
但是curl 更快
最快的是curl_multi,因为这样你可以一次发送数百个请求。

Here is a nice demo 让您开始。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-04
    • 1970-01-01
    • 2023-04-02
    相关资源
    最近更新 更多