Curl不会连接到工作代理



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

<?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

我已经测试了代理,它已经在线了,这应该对你有用:

$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;

最新更新