我假设您已尝试将超时设置为 0。
这些站点返回什么 HTTP 状态代码?检查curl_getinfo($ch, CURLINFO_HTTP_CODE);
。
其他尝试可能是欺骗 User-Agent 标头,可能使用您自己的浏览器的标头,因为您知道可以访问这些页面。他们可能只是试图阻止机器人访问该页面。
调查标头和 http 代码应该可以为您提供更多信息。
编辑:
我对此进行了更多研究。一件事是您的连接超时有一个错字 - 应该是CURLOPT_CONNECTTIMEOUT
.
无论如何,我运行了这个脚本(如下),它返回了你正在寻找的东西(我认为)。检查它和你的有什么不同。如果有帮助,我正在使用 PHP 5.2.8。
<?php
$addresses = array(
'http://atensembl.arabidopsis.info/Arabidopsis_thaliana_TAIR/unisearch?species=Arabidopsis_thaliana_TAIR;idx=;q=At5g02310',
'http://www.bar.utoronto.ca/efp/cgi-bin/efpWeb.cgi?dataSource=Chemical&modeInput=Absolute&primaryGene=At5g02310&orthoListOn=0'
);
foreach ($addresses as $address) {
echo "Address: http://www.bar.utoronto.ca/efp/cgi-bin/efpWeb.cgi?dataSource=Chemical&modeInput=Absolute&primaryGene=At5g02310&orthoListOn=0\n";
// This box doesn't have http registered as a transport layer - pfft
//var_dump(fsockopen($address, 80));
$ch = curl_init($address);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
$fc = curl_exec($ch);
echo "Info: " . print_r(curl_getinfo($ch), true) . "\n";
echo "$fc\n";
curl_close($ch);
}
它返回以下内容(TL;DR:我的 cURL 可以很好地阅读页面):
C:\Users\Ross>php -e D:\sandbox\curl.php
Address: http://www.bar.utoronto.ca/efp/cgi-bin/efpWeb.cgi?dataSource=Chemical&modeInput=Absolute&primaryGene=At5g02310&orthoListOn=0
Info: Array
(
[url] => http://atensembl.arabidopsis.info/Arabidopsis_thaliana_TAIR/unisearch?species=Arabidopsis_thaliana_TAIR;idx=;q=At5g02310
[content_type] => text/html; charset=ISO-8859-1
[http_code] => 200
[header_size] => 168
[request_size] => 151
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 0.654
[namelookup_time] => 0.004
[connect_time] => 0.044
[pretransfer_time] => 0.044
[size_upload] => 0
[size_download] => 7531
[speed_download] => 11515
[speed_upload] => 0
[download_content_length] => 0
[upload_content_length] => 0
[starttransfer_time] => 0.57
[redirect_time] => 0
)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-gb" lang="en-gb">
<head>
<title>AtEnsembl release 49: Arabidopsis thaliana TAIR EnsEMBL UniSearch results</title>
<style type="text/css" media="all">
@import url(/css/ensembl.css);
@import url(/css/content.css);
</style>
<style type="text/css" media="print">
@import url(/css/printer-styles.css);
</style>
<style type="text/css" media="screen">
@import url(/css/screen-styles.css);
</style>
<script type="text/javascript" src="/js/protopacked.js"></script>
<script type="text/javascript" src="/js/core42.js"></script>
<!-- Snipped for freedom - lots of lines -->
</body>
</html>
Address: http://www.bar.utoronto.ca/efp/cgi-bin/efpWeb.cgi?dataSource=Chemical&modeInput=Absolute&primaryGene=At5g02310&orthoListOn=0
Info: Array
(
[url] => http://www.bar.utoronto.ca/efp/cgi-bin/efpWeb.cgi?dataSource=Chemical&modeInput=Absolute&primaryGene=At5g02310&orthoListOn=0
[content_type] => text/html; charset=UTF-8
[http_code] => 200
[header_size] => 146
[request_size] => 155
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 2.695
[namelookup_time] => 0.004
[connect_time] => 0.131
[pretransfer_time] => 0.131
[size_upload] => 0
[size_download] => 14156
[speed_download] => 5252
[speed_upload] => 0
[download_content_length] => 0
[upload_content_length] => 0
[starttransfer_time] => 2.306
[redirect_time] => 0
)
<html>
<head>
<title>Arabidopsis eFP Browser</title>
<link rel="stylesheet" type="text/css" href="efp.css"/>
<link rel="stylesheet" type="text/css" href="domcollapse.css"/>
<script type="text/javascript" src="efp.js"></script>
<script type="text/javascript" src="domcollapse.js"></script>
</head>
<body>
<!-- SANITY SNIP -->
</body>
</html>
那么这意味着什么?不完全确定。我怀疑他们是否专门阻止了您(因为您可以访问该页面,除非您在网络服务器上运行此脚本)。尝试在上面运行我的代码 - 如果可行,请尝试注释掉部分代码以查看有什么不同(并可能导致停止)。还有你运行的是什么 PHP 版本?