fsockopen()已启用但不起作用

时间:2014-02-25 23:15:33

标签: php fsockopen

我使用此代码检查了fsockopen并启用了该功能。

<?php
if(function_exists('fsockopen')) {
     echo "fsockopen function is enabled";
}
else {
     echo "fsockopen is not enabled";
}
?>

以下是我需要使用的脚本使用的代码。它返回错误:fsockopen-function无法正常工作,错误:110连接超时 - FAILED

if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") $url = "https://";
else $url = "http://";
$url .= $HTTP_HOST.$REQUEST_URI;
$querystring = "action=fsockopentest";
if (@strpos($url, "/", 8)) {
    $urlpath = "/".substr($url, strpos($url, "/", 8)+1);
    $urldomain = substr($url, 0, strpos($url, "/", 8));
} else {
    $urlpath = "/";
    $urldomain = $url;
}
$urldomain = str_replace("http://", "", $urldomain);
$postheader = "POST $urlpath HTTP/1.0\r\nHost: $urldomain\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: ".strlen ($querystring)."\r\n\r\n";
$fp = @fsockopen ($urldomain, 80, $errno, $errstr, 10);
$res = "";
if ($fp) {
    fputs ($fp, $postheader.$querystring);
    while (!feof($fp)) $res .= fgets ($fp, 1024);
    fclose ($fp);
}
if (strstr($res,"SUCCESS")) echo "<li>The fsockopen-function is working - <font color=\"#009900\">PASSED</font></li>";
else echo "<li>The fsockopen-function isn't working, error: $errno $errstr - <font color=\"#FF0000\">FAILED</font></li>";

echo "</ul>";

可能出现什么问题?

1 个答案:

答案 0 :(得分:0)

error: 110 Connection timed out - FAILED

是fsocks函数无法连接到在指定时间内给出的服务器的结果。

这可能是网址的问题,或者您没有给超时足够长的时间。