我正在尝试使用fsockopen()来获取远程内容。在大多数SSL站点上,脚本可以正常运行。但是在某些特定站点上脚本失败。这是我的剧本
<?php
$response = null;
$host = "";
$handle = fsockopen("ssl://$host", 443, $errno, $errstr, 90);
$header = "GET / HTTP/1.1\r\n";
$header .= "Host: $host\r\n";
$header .= "Accept-Language: en-US,en;q=0.5\r\n";
$header .= "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n";
$header .= "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:16.0) Gecko/20100101 Firefox/16.0\r\n";
$header .= "Referer: https://$host\r\n";
$header .= "Connection: Close\r\n\r\n";
fwrite($handle, $header);
while (!feof($handle))
{
$response .= fgets($handle, 32768);
}
fclose($handle);
echo $response;
当$host
为browserlab.adobe.com
时,连接将超时。当$host
为mediafire.com
时,服务器没有响应。我的计算机上没有阻止端口443,并且在Web浏览器上连接到这些站点就可以了。
脚本在XAMPP上运行,PHP v5.4.7和Apache v2.4.2,启用了OpenSSL扩展。我在旧版本的XAMPP上试用了PHP v5.3.5和Apache v2.2.17,并且脚本正常工作。
所以有人能告诉我为什么这么做吗?