fopen"无法打开流:HTTP请求失败!"有时

时间:2018-05-29 17:06:42

标签: php cross-domain fopen

所以我正在做一些PHP Corss-Origin Processing和Tunneling。在远程服务器上,我有一个PHP编译一些文件,这可能需要一段时间,具体取决于请求的文件。从另一台服务器,我执行以下操作:

$file = "http://".$remote."/remote.php?prj=".$getprj;
$filename = substr($file,strrpos($file,"/")+1);
$fp = fopen($file, "r") or die("DEAD");
if(!headers_sent())
{
// http://php.net/manual/en/function.header.php#86554
//  header("Content-Disposition: attachment; filename=".$filename);
header("Content-Disposition: attachment; "
.sprintf('filename="%s"; ', rawurlencode($filename))
.sprintf("filename*=utf-8''%s", rawurlencode($filename)));
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header("Content-Description: File Transfer");
//  header("Content-Length: " . filesize($filename));
}
flush(); // this doesn't really matter.

while (!feof($fp))
{
    echo fread($fp, 65536);
    flush(); // this is essential for large downloads
}
fclose($fp);

当我提出一个请求时,几秒钟后它就会提供下载。当我提出另一个请求时,经过一段时间后会再次出现上述错误。

Warning: fopen(http://that.remote.server/remote.php?prj=tnt3): failed to open stream: HTTP request failed! in /.../current.php on line 18 DEAD

我几乎怀疑超时,但无法set_time_limit我无法确定。我有什么选择?

1 个答案:

答案 0 :(得分:-1)

在错误消息中," current.php"是您尝试打开文件还是其他URI的一部分?因为这" ..."看起来很奇怪......