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

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

      1. PHP/Curl:HEAD Request 在某些网站上需要很长时间

        PHP / Curl: HEAD Request takes a long time on some sites(PHP/Curl:HEAD Request 在某些网站上需要很长时间)

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

                <bdo id='UaFku'></bdo><ul id='UaFku'></ul>
                <legend id='UaFku'><style id='UaFku'><dir id='UaFku'><q id='UaFku'></q></dir></style></legend>

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

                  <tbody id='UaFku'></tbody>

                  本文介绍了PHP/Curl:HEAD Request 在某些网站上需要很长时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个简单的代码,它对 URL 进行头部请求,然后打印响应头.我注意到在某些网站上,这可能需要很长时间才能完成.

                  I have simple code that does a head request for a URL and then prints the response headers. I've noticed that on some sites, this can take a long time to complete.

                  例如,请求 http://www.arstechnica.com 大约需要两分钟.我使用另一个执行相同基本任务的网站尝试了相同的请求,它立即返回.所以一定是我设置不正确导致了这个延迟.

                  For example, requesting http://www.arstechnica.com takes about two minutes. I've tried the same request using another web site that does the same basic task, and it comes back immediately. So there must be something I have set incorrectly that's causing this delay.

                  这是我的代码:

                  $ch = curl_init();
                  curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
                  curl_setopt ($ch, CURLOPT_URL, $url);
                  curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 20);
                  curl_setopt ($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
                  
                  // Only calling the head
                  curl_setopt($ch, CURLOPT_HEADER, true); // header will be at output
                  curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'HEAD'); // HTTP request is 'HEAD'
                  
                  $content = curl_exec ($ch);
                  curl_close ($ch);
                  

                  这里有一个指向具有相同功能的网站的链接:http://www.seoconsultants.com/tools/headers.asp

                  Here's a link to the web site that does the same function: http://www.seoconsultants.com/tools/headers.asp

                  上面的代码,至少在我的服务器上,需要两分钟才能检索 www.arstechnica.com,但上面链接中的服务会立即返回它.

                  The code above, at least on my server, takes two minutes to retrieve www.arstechnica.com, but the service at the link above returns it right away.

                  我错过了什么?

                  推荐答案

                  试着简化一下:

                  print htmlentities(file_get_contents("http://www.arstechnica.com"));
                  

                  上面的输出立即在我的网络服务器上.如果您没有,那么您的网络托管服务商很可能有某种设置来限制此类请求.

                  The above outputs instantly on my webserver. If it doesn't on yours, there's a good chance your web host has some kind of setting in place to throttle these kind of requests.

                  编辑:

                  由于上述情况会立即发生,请尝试设置 此 curl 设置 在您的原始代码上:

                  Since the above happens instantly for you, try setting this curl setting on your original code:

                  curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, true);
                  

                  使用您发布的工具,我注意到 http://www.arstechnica.com 为发送给它的任何请求发送了 301 标头.cURL 可能会得到这个并且没有遵循为其指定的新位置,从而导致您的脚本挂起.

                  Using the tool you posted, I noticed that http://www.arstechnica.com has a 301 header sent for any request sent to it. It is possible that cURL is getting this and not following the new Location specified to it, thus causing your script to hang.

                  第二次编辑:

                  奇怪的是,尝试与上面相同的代码也导致我的网络服务器挂起.我替换了这段代码:

                  Curiously enough, trying the same code you have above was making my webserver hang too. I replaced this code:

                  curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'HEAD'); // HTTP request is 'HEAD'
                  

                  有了这个:

                  curl_setopt($ch, CURLOPT_NOBODY, true);
                  

                  手册建议您采用哪种方式头请求.它使它立即工作.

                  Which is the way the manual recommends you do a HEAD request. It made it work instantly.

                  这篇关于PHP/Curl:HEAD Request 在某些网站上需要很长时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                  PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                  mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                  Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                  Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                  Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)
                  <i id='aHaKS'><tr id='aHaKS'><dt id='aHaKS'><q id='aHaKS'><span id='aHaKS'><b id='aHaKS'><form id='aHaKS'><ins id='aHaKS'></ins><ul id='aHaKS'></ul><sub id='aHaKS'></sub></form><legend id='aHaKS'></legend><bdo id='aHaKS'><pre id='aHaKS'><center id='aHaKS'></center></pre></bdo></b><th id='aHaKS'></th></span></q></dt></tr></i><div id='aHaKS'><tfoot id='aHaKS'></tfoot><dl id='aHaKS'><fieldset id='aHaKS'></fieldset></dl></div>
                    <tbody id='aHaKS'></tbody>

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

                      • <small id='aHaKS'></small><noframes id='aHaKS'>

                          <tfoot id='aHaKS'></tfoot>
                          <legend id='aHaKS'><style id='aHaKS'><dir id='aHaKS'><q id='aHaKS'></q></dir></style></legend>