【问题标题】:fopen "failed to open stream: HTTP request failed!" sometimesfopen "打开流失败:HTTP 请求失败!"有时
【发布时间】:2018-05-30 01:11:28
【问题描述】:

所以我正在做一些 PHP Corss-Origin 处理和隧道。在远程服务器上,我有一个 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 我无法确定这一点。我在这里有什么选择?

【问题讨论】:

    标签: php cross-domain fopen


    【解决方案1】:

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

    【讨论】:

    • 你应该在 cmets 中包含这个
    • @Emeeus 他对 cme​​ts 没有足够的声誉。 @Fran current.php 是带有fopen 的那个。 /.../ 是我省略的客户、号码、httpd 等的绝对路径。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-06-23
    • 1970-01-01
    • 2010-10-16
    • 2020-08-06
    • 2020-12-18
    • 1970-01-01
    • 2012-04-08
    相关资源
    最近更新 更多