卷曲不会连接到工作代理

时间:2014-04-23 17:01:56

标签: php curl

我最近更新了php到5.3.28,由于某种原因curl无法连接到代理,它超时了。我设置了一个小测试来检查它,它在一台服务器上使用php5.3.27运行正常但不在这一台上。 testcode:

<?php

$proxy=$argv[1];

echo "Testing Proxy Status ...\n";
$testpage = "http://mydmain626.serveftp.com/rd/index.shtml";
$ch = curl_init($testpage);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_MAXREDIRS, 2);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20);
curl_setopt($ch, CURLOPT_TIMEOUT, 25);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
$page = curl_exec($ch);
$info = curl_getinfo($ch);
$code = $info;
echo $page;
curl_close($ch);


?>

以:php curl_test.php 213.220.218.14:21320

运行

输出:

Testing Proxy Status ...
* About to connect() to proxy 213.220.218.14 port 21320 (#0)
*   Trying 213.220.218.14... * Timeout
* connect() timed out!
* Closing connection #0

何时输出:

Testing Proxy Status ...
* About to connect() to proxy 213.220.218.14 port 21320 (#0)
*   Trying 213.220.218.14... * connected
* Connected to 213.220.218.14 (213.220.218.14) port 21320 (#0)
> GET http://mydmain626.serveftp.com/rd/index.shtml HTTP/1.1
Host: mydmain626.serveftp.com
Accept: */*
Proxy-Connection: Keep-Alive

< HTTP/1.1 200 OK
< Date: Wed, 23 Apr 2014 16:47:28 GMT
< Server: Apache/2
< Accept-Ranges: bytes
< Vary: Accept-Encoding,User-Agent
< Content-Length: 69
< Keep-Alive: timeout=1, max=100
< Connection: Keep-Alive
< Content-Type: text/html
<
* Connection #0 to host 213.220.218.14 left intact
<html>
<head>
</head>
<body>
<br>proxy_says_alive<br>
</body>
</html>* Closing connection #0

1 个答案:

答案 0 :(得分:1)

我已经测试了代理并且它在线,这应该适合你:

$url = 'http://dynupdate.no-ip.com/ip.php';
$proxy = '213.220.218.14:21320';
//$proxyauth = 'user:password';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
//curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyauth);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
$curl_scraped_page = curl_exec($ch);
curl_close($ch);

echo $curl_scraped_page;