zoukankan      html  css  js  c++  java
  • curl常用设置-涉及超时相关

    curl_easy_setopt( curl, CURLOPT_VERBOSE, 1L ); //在屏幕打印请求连接过程和返回http数据
    curl_easy_setopt( curl, CURLOPT_TIMEOUT, 10 );//接收数据时超时设置,如果10秒内数据未接收完,直接退出
    curl_easy_setopt(curl, CURLOPT_AUTOREFERER, 1); // 以下3个为重定向设置
    curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1); //返回的头部中有Location(一般直接请求的url没找到),则继续请求Location对应的数据 
    curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 1);//查找次数,防止查找太深
    curl_easy_setopt( curl, CURLOPT_CONNECTTIMEOUT, 3 );//连接超时,这个数值如果设置太短可能导致数据请求不到就断开了

    转自:http://blog.csdn.net/lizhi200404520/article/details/7369658

    ==========================================

    以及下面实际运用相关代码段:

    foreach ($url_array as $url) {
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_HEADER, 0);
            curl_setopt($ch, CURLOPT_TIMEOUT, 50);
            curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; Baiduspider/2.0; +http://www.baidu.com/search/spider.html)");
            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);        // 使用自动跳转 
            curl_setopt($ch, CURLOPT_MAXREDIRS, 7);
            curl_setopt($ch, CURLOPT_REFERER, $url);
            curl_setopt($ch, CURLOPT_ENCODING, "gzip");
            if ($pCookie != "") {
                curl_setopt($ch, CURLOPT_COOKIEFILE, $pCookie); // 读取上面所储存的Cookie信息 
            }
            curl_multi_add_handle($mh, $ch); // 把 curl resource 放进 multi curl handler 里
            $handle[$i++] = $ch;
        }

    摘自:http://bbs.csdn.net/topics/380152499

  • 相关阅读:
    MyEclipse 自带的TomCat 新增部署的时候不显示 Deploy Location
    No prohects are avaliable for deployment to this server
    Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
    Dom4j 对XMl解析 新手学习,欢迎高手指正
    电脑的技巧
    Browserify的基本使用
    bower的基本使用
    前端工程化--前端工程化技术栈
    前端工程化--架构说明
    前端工程化-前端工程化说明
  • 原文地址:https://www.cnblogs.com/wainiwann/p/3494391.html
Copyright © 2011-2022 走看看