V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
nmdx
V2EX  ›  PHP

PHP curl 无法使用非 80 端口的代理?

  •  
  •   nmdx · 2017-07-22 20:06:29 +08:00 · 42553 次点击
    这是一个创建于 2441 天前的主题,其中的信息可能已经有所发展或是发生改变。

    困扰了好久的问题。。代码如下

    "; } $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); if( $httpcode ==200 ) { echo ($i+1).". $dl $httpcode 成功
    "; } } curl_close($ch); ?>
    1. 94.141.244.132:8081 失败
    2. 70.164.255.173:8080 失败
    3. 46.38.52.36:8081 失败
    4. 125.162.129.58:3128 失败
    5. 67.47.234.249:87 失败
    6. 112.252.16.104:8889 失败
    7. 120.77.155.249:8888 失败
    8. 43.245.191.74:8080 失败
    9. 190.104.178.46:8080 失败
    10. 200.108.35.60:8087 失败
    11. 174.32.124.214:87 失败
    12. 50.206.232.202:3128 失败
    13. 109.108.87.136:53281 失败
    14. 110.78.158.64:3128 失败
    15. 66.118.122.3:53281 失败
    16. 83.241.46.175:8080 失败
    17. 113.121.249.95:808 失败
    18. 174.32.125.242:87 失败
    19. 39.50.237.57:8080 失败
    20. 72.169.144.210:87 失败

    有些 ip 是能在手机上测试通过的。。换了一个环境跑还是一样结果,所以,是不是代码有些问题╮( •́ω•̀ )╭

    第 1 条附言  ·  2017-11-19 12:25:03 +08:00
    今天换了 vps 跑正常了。。。如果你用的虚拟空间 /主机 可能就是你的主机商设置问题 联系反馈吧
    11 条回复    2018-05-17 22:33:47 +08:00
    nmdx
        1
    nmdx  
    OP
       2017-07-22 20:08:43 +08:00 via Android
    header('Content-Type: text/html; charset=utf-8');
    $ip=array(.......);//ip:port

    for ($i=0; $i<=count($ip) -1; $i++) {
    $dl= $ip[$i];
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_PROXY, $dl );
    curl_setopt($ch, CURLOPT_URL, "http://baidu.com");
    curl_setopt($ch, CURLOPT_HEADER, 1);
    curl_setopt($ch, CURLOPT_NOBODY, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 5);
    curl_setopt ($ch, CURLOPT_TIMEOUT, 5);
    curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
    if (!curl_exec($ch)) { echo ($i+1).". $dl 失败<br>"; }
    $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    if( $httpcode ==200 )
    {
    echo ($i+1).". $dl $httpcode 成功<br>";
    }
    }
    curl_close($ch);
    fuxkcsdn
        2
    fuxkcsdn  
       2017-07-23 09:14:01 +08:00 via iPhone
    $ip=array(.......);//ip:port
    改为
    $ip=array(.......);// http://ip:port
    VgV
        3
    VgV  
       2017-07-23 13:46:05 +08:00
    @fuxkcsdn 不用加 http://也是可以的,原因是他漏写了一段代码。
    curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
    nmdx
        4
    nmdx  
    OP
       2017-07-23 16:08:49 +08:00
    @VgV 应该不是这个问题。。CURLOPT_PROXYTYPE 的默认值不就是 CURLPROXY_HTTP 嘛。。添加已测试。。
    加了一下 curl_error 如下:
    1Failed to connect to 189.17.39.3 port 8080: Connection refused. 189.17.39.3:8080 失败
    2Failed to connect to 97.72.129.38 port 87: Connection refused. 97.72.129.38:87 失败
    3Failed to connect to 139.59.110.186 port 8080: Connection refused. 139.59.110.186:8080 失败
    4Failed to connect to 122.241.74.202 port 808: Connection refused. 122.241.74.202:808 失败
    5Failed to connect to 112.74.50.191 port 8888: Connection refused. 112.74.50.191:8888 失败
    6Failed to connect to 218.75.101.66 port 3128: Connection refused. 218.75.101.66:3128 失败
    7Failed to connect to 115.207.81.119 port 808: Connection refused. 115.207.81.119:808 失败
    8Failed to connect to 59.62.164.37 port 808: Connection refused. 59.62.164.37:808 失败
    9. 183.222.102.108:80 200 成功
    10Failed to connect to 148.251.160.237 port 3128: Connection refused. 148.251.160.237:3128 失败
    ===略
    VgV
        5
    VgV  
       2017-07-23 23:17:55 +08:00
    @nmdx 不是成功了一个吗,可能是你的这些 IP 有问题,失效了。。
    curl_setopt($ch, CURLOPT_PROXY, $proxy);//ip:port
    curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);//必须要加这行
    fuxkcsdn
        6
    fuxkcsdn  
       2017-07-24 09:29:45 +08:00 via iPhone
    @VgV
    curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP)
    和用 http:// ip:port 那是一样效果滴…
    VgV
        7
    VgV  
       2017-07-24 11:39:22 +08:00
    @fuxkcsdn 因为我看他的格式,所以让他加这行进去。
    nmdx
        8
    nmdx  
    OP
       2017-07-25 03:47:58 +08:00 via Android
    @VgV 因为那个是 80 口的嘛。。。比如这个挂在阿里云的 112.74.50.191:8888 手机可用

    p.s.也就是说代码应该是暂时没啥问题了?那可能是环境的问题了。。 没环境测试了(•́ω•̀ ٥)
    nmdx
        9
    nmdx  
    OP
       2017-07-25 03:52:20 +08:00 via Android
    @VgV ps...你们说的那个 ip:port 的问题。。表示直接一行 curl_setopt($ch, CURLOPT_PROXY, "ip:port" );就可以的。。 大概因为 http 是默认值?
    ja2007gg
        10
    ja2007gg  
       2018-04-22 14:20:11 +08:00
    请问你解决问题了吗?我也遇到 Curl error: Recv failure: Connection reset by peer 这个问题 而且还没有解决
    nmdx
        11
    nmdx  
    OP
       2018-05-17 22:33:47 +08:00 via Android
    @ja2007gg 这个是代理过载了 代理那边性能或者设置问题。。(大概😂)
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2957 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 11:06 · PVG 19:06 · LAX 04:06 · JFK 07:06
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.