<i id='BNo4t'><tr id='BNo4t'><dt id='BNo4t'><q id='BNo4t'><span id='BNo4t'><b id='BNo4t'><form id='BNo4t'><ins id='BNo4t'></ins><ul id='BNo4t'></ul><sub id='BNo4t'></sub></form><legend id='BNo4t'></legend><bdo id='BNo4t'><pre id='BNo4t'><center id='BNo4t'></center></pre></bdo></b><th id='BNo4t'></th></span></q></dt></tr></i><div id='BNo4t'><tfoot id='BNo4t'></tfoot><dl id='BNo4t'><fieldset id='BNo4t'></fieldset></dl></div>
    <tfoot id='BNo4t'></tfoot>

    <legend id='BNo4t'><style id='BNo4t'><dir id='BNo4t'><q id='BNo4t'></q></dir></style></legend>

      <small id='BNo4t'></small><noframes id='BNo4t'>

        <bdo id='BNo4t'></bdo><ul id='BNo4t'></ul>

      如何加速php中的cURL?

      时间:2023-09-24
        <tbody id='0sZL4'></tbody>
        <legend id='0sZL4'><style id='0sZL4'><dir id='0sZL4'><q id='0sZL4'></q></dir></style></legend>
          • <bdo id='0sZL4'></bdo><ul id='0sZL4'></ul>
            <tfoot id='0sZL4'></tfoot>

            <small id='0sZL4'></small><noframes id='0sZL4'>

            1. <i id='0sZL4'><tr id='0sZL4'><dt id='0sZL4'><q id='0sZL4'><span id='0sZL4'><b id='0sZL4'><form id='0sZL4'><ins id='0sZL4'></ins><ul id='0sZL4'></ul><sub id='0sZL4'></sub></form><legend id='0sZL4'></legend><bdo id='0sZL4'><pre id='0sZL4'><center id='0sZL4'></center></pre></bdo></b><th id='0sZL4'></th></span></q></dt></tr></i><div id='0sZL4'><tfoot id='0sZL4'></tfoot><dl id='0sZL4'><fieldset id='0sZL4'></fieldset></dl></div>
                本文介绍了如何加速php中的cURL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我正在尝试从 Twitter 嵌入推文.所以,我使用 cURL 来取回 json.我写了一个小测试,但测试大约需要 5 秒,当我在本地运行时.所以,我不确定我在这里做错了什么.

                I'm trying to get embed tweet from Twitter. So, I'm using cURL to get the json back. I wrote a little test but the test takes around 5 seconds as well as when I run locally. So, I'm not sure what am I doing wrong here.

                public function get_tweet_embed($tw_id) {
                
                    $json_url = "https://api.twitter.com/1/statuses/oembed.json?id={$tw_id}&align=left&omit_script=true&hide_media=false";
                
                    $ch = curl_init( $json_url );
                    $start_time = microtime(TRUE);
                    $JSON = curl_exec($ch);
                    $end_time = microtime(TRUE);
                    echo $end_time - $start_time; //5.7961111068726
                
                    return $this->get_html($JSON);
                }
                
                private function get_html($embed_json) {
                    $JSON_Data = json_decode($embed_json,true);
                    $tw_embed_code = $JSON_Data["html"];
                    return $tw_embed_code;
                }
                

                当我粘贴链接并从浏览器进行测试时,速度非常快.

                When I paste the link and test it from the browser it's really fast.

                推荐答案

                关于环境,我在 PHP 中观察到,cURL 通常在大多数环境中运行得非常快,除了在 CPU 低且网络较慢的地方表现.例如,在我的 MAMP 安装的 localhost 上,curl 很快,在较大的亚马逊实例上,curl 很快.但是在一个糟糕的小型主机上,我看到它存在性能问题,连接速度明显变慢.不过,我不确定为什么会变慢.此外,它肯定不会慢 5 秒.

                With respect to environment, I've observed in PHP that cURL typically runs very fast in most environments except in places where there is low CPU and there is slower network performance. For example, on localhost on my MAMP installation, curl is fast, on a larger amazon instance, curl is fast. But on a small crappy hosting, i've seen it have performance issues where it is noticeably slower to connect. Though, i'm not sure exactly why that is slower. Also, it sure wasn't 5 seconds slower.

                为了帮助确定是 PHP 还是您的环境,您应该尝试通过命令行与 curl 交互.至少,如果还有 5 秒,您就可以排除 PHP 代码的问题.

                to help determine if its PHP or your environment, you should try interacting with curl via the command line. At least that you'll be able to rule out PHP code being the problem if its still 5 seconds.

                这篇关于如何加速php中的cURL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:Twitter 中的关注者数量 下一篇:从 PHP 中的字符串中提取 Twitter 标签

                相关文章

                最新文章

                <i id='CPHMt'><tr id='CPHMt'><dt id='CPHMt'><q id='CPHMt'><span id='CPHMt'><b id='CPHMt'><form id='CPHMt'><ins id='CPHMt'></ins><ul id='CPHMt'></ul><sub id='CPHMt'></sub></form><legend id='CPHMt'></legend><bdo id='CPHMt'><pre id='CPHMt'><center id='CPHMt'></center></pre></bdo></b><th id='CPHMt'></th></span></q></dt></tr></i><div id='CPHMt'><tfoot id='CPHMt'></tfoot><dl id='CPHMt'><fieldset id='CPHMt'></fieldset></dl></div>
                  <bdo id='CPHMt'></bdo><ul id='CPHMt'></ul>
                <tfoot id='CPHMt'></tfoot>

                <legend id='CPHMt'><style id='CPHMt'><dir id='CPHMt'><q id='CPHMt'></q></dir></style></legend>

                  1. <small id='CPHMt'></small><noframes id='CPHMt'>