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

2017-07-22 20:06:29 +08:00
 nmdx

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

"; } $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 是能在手机上测试通过的。。换了一个环境跑还是一样结果,所以,是不是代码有些问题╮( •́ω•̀ )╭

42706 次点击
所在节点    PHP
11 条回复
nmdx
2017-07-22 20:08:43 +08:00
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
2017-07-23 09:14:01 +08:00
$ip=array(.......);//ip:port
改为
$ip=array(.......);// http://ip:port
VgV
2017-07-23 13:46:05 +08:00
@fuxkcsdn 不用加 http://也是可以的,原因是他漏写了一段代码。
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
nmdx
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
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
2017-07-24 09:29:45 +08:00
@VgV
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP)
和用 http:// ip:port 那是一样效果滴…
VgV
2017-07-24 11:39:22 +08:00
@fuxkcsdn 因为我看他的格式,所以让他加这行进去。
nmdx
2017-07-25 03:47:58 +08:00
@VgV 因为那个是 80 口的嘛。。。比如这个挂在阿里云的 112.74.50.191:8888 手机可用

p.s.也就是说代码应该是暂时没啥问题了?那可能是环境的问题了。。 没环境测试了(•́ω•̀ ٥)
nmdx
2017-07-25 03:52:20 +08:00
@VgV ps...你们说的那个 ip:port 的问题。。表示直接一行 curl_setopt($ch, CURLOPT_PROXY, "ip:port" );就可以的。。 大概因为 http 是默认值?
ja2007gg
2018-04-22 14:20:11 +08:00
请问你解决问题了吗?我也遇到 Curl error: Recv failure: Connection reset by peer 这个问题 而且还没有解决
nmdx
2018-05-17 22:33:47 +08:00
@ja2007gg 这个是代理过载了 代理那边性能或者设置问题。。(大概😂)

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/377249

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX