zoukankan      html  css  js  c++  java
  • PHP CURL 抓取失败 自己调试

    蛋疼的一下午,物理机win7旗舰版+APACHE2 ,CURL抓取一直成功。 虚拟机ubuntu+apache2一直抓取失败。

    晚上,问个仁兄才知道,CURL可以调试: 参考这位兄台: 地址

    curl_errno 和 curl_error 函数,分别返回 HTTP 的错误代码和错误类别。例如:
    
    <?php
    $ch = curl_init('http://www.soso.com/');
    curl_exec($ch);
    if (curl_errno($ch)) {
        echo 'Curl error: ' . curl_error($ch);
    }
    curl_close($ch);
    ?>
    
    返回:
    
    Curl error: couldn't connect to host

    我嘞个去,无法连接www.soso.com 是怎么回事,DNS错误找不到IP?ping www.soso.com 也是OK的。 ping的通

    $ch = curl_init('http://www.soso.com/');
    curl_setopt($ch, CURLINFO_HEADER_OUT, true);//curl_getinfo 函数返回的数组将包含 cURL 请求的 header 信息
    curl_setopt($ch, CURLOPT_HEADER , true);//回应的 header 信息
    curl_exec($ch);
    if (curl_errno($ch)) {
        var_dump(curl_getinfo($ch));
        var_dump('Curl error: ' . curl_error($ch));
    }
    curl_close($ch);
    
    依旧是那些看不懂的信息一大堆:
    
    
    array(22) {
      ["url"]=>
      string(20) "http://www.soso.com/"
      ["content_type"]=>
      NULL
      ["http_code"]=>
      int(0)
      ["header_size"]=>
      int(0)
      ["request_size"]=>
      int(0)
      ["filetime"]=>
      int(-1)
      ["ssl_verify_result"]=>
      int(0)
      ["redirect_count"]=>
      int(0)
      ["total_time"]=>
      float(63.127513)
      ["namelookup_time"]=>
      float(2.0E-5)
      ["connect_time"]=>
      float(0)
      ["pretransfer_time"]=>
      float(0)
      ["size_upload"]=>
      float(0)
      ["size_download"]=>
      float(0)
      ["speed_download"]=>
      float(0)
      ["speed_upload"]=>
      float(0)
      ["download_content_length"]=>
      float(-1)
      ["upload_content_length"]=>
      float(-1)
      ["starttransfer_time"]=>
      float(0)
      ["redirect_time"]=>
      float(0)
      ["certinfo"]=>
      array(0) {
      }
      ["redirect_url"]=>
      string(0) ""
    }
    string(36) "Curl error: couldn't connect to host"

    最后,还是没办法。试一下wget 抓www.soso.com 我怀疑网络很有问题。

    大概5分钟后,终于成功抓取到了一次www.soso.com页面。 5分钟啊,C.网络肯定有问题

    路由追踪下:

    root@ubuntu:~# tracepath www.soso.com
    1: 142.54.182.194 0.071ms pmtu 1500 1: 142.54.182.193 0.475ms 1: 142.54.182.193 0.468ms 2: 192.187.107.125 0.311ms 3: 69.30.209.137 0.598ms 4: te0-3-0-4.mpd22.mci01.atlas.cogentco.com 0.625ms 5: be2141.ccr22.dfw01.atlas.cogentco.com 10.982ms 6: be2032.ccr21.dfw03.atlas.cogentco.com 11.210ms 7: 4.68.111.101 21.825ms asymm 11 8: vlan80.csw3.Dallas1.Level3.net 54.881ms asymm 12 9: ae-93-93.ebr3.Dallas1.Level3.net 55.135ms asymm 12 10: ae-3-3.ebr2.LosAngeles1.Level3.net 55.265ms asymm 12 11: ae-72-72.csw2.LosAngeles1.Level3.net 55.357ms 12: ae-4-90.edge6.LosAngeles1.Level3.net 55.118ms asymm 11 13: 59.43.182.89 46.536ms asymm 12 14: 59.43.182.149 53.360ms asymm 11 15: 59.43.182.150 203.715ms asymm 13 16: 59.43.248.254 203.674ms asymm 14 17: 202.55.1.246 204.871ms asymm 14 18: no reply 19: no reply 20: no reply 21: no reply 22: no reply 23: no reply 24: no reply 25: no reply 26: no reply 27: no reply 28: no reply 29: no reply 30: no reply 31: no reply Too many hops: pmtu 1500 Resume: pmtu 1500

    拿美国2台服务器跟踪路由试一下, 发现都是一模一样的 . 第18个开始失败, 但是另一台却可以正常CURL,和WGET. 卧槽,奇怪。

    下个结论吧,SOSO BAIDU都有抓取频率限制。不过至少比SOGOU好多了,SOGOU根本不允许抓。

    SOSO BAIDU抓取频率设置还是很高的,一般一秒抓一个我看都没事。 估计我的服务器IP已经被封了吧。心碎!

  • 相关阅读:
    MVC调用SVC无法找到资源解决问题
    动态更改iframe src
    http改成https wcf 配置更改
    Nuget 管理报repositories.config 访问路径被拒绝 解决办法
    如何在水晶报表中动态添加字段
    VS2.0控件之日历《Calendar》C#
    C#操作Excel全源码
    如何向水晶报表数据源中的存储过程传参数……
    公式的典型用途
    水晶报表公式使用必读
  • 原文地址:https://www.cnblogs.com/qunshu/p/3367357.html
Copyright © 2011-2022 走看看