dqzg62440 2014-07-21 13:54
浏览 132

浏览器提示:example.com上的服务器响应时间过长

On the client side a user clicks a download button, the (apache) webserver (and PHP5.4) then creates a very large file which upon completion must be send to the client side. Because it takes a while to create this (huge) file the browser (FF) after 5 minutes prompt with the message: "The connection has timed out: the server at 10.0.0.100 is taking too long to respond".

On my php page I've set a large timeout: set_time_limit(3600); but this doesn't help. I tried echo-ing a white space before the server generates the file, to let the browser know there is a response, but that trick sends the content of the file into the browser itself which is not what I want.

As headers I am using, but I think this is not the issue as the browser times-out before anything is sent from the server :

$size=  filesize($path);
$fname = basename ($path);    
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=\"".$fname."\"");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".$size);
header("Content-type: application/octet-stream");
ob_clean();
flush();
readfile($path);
exit;

Any ideas on how to solve this problem? Maybe there is a javascript way?

  • 写回答

1条回答 默认 最新

  • dsqdpn31467 2014-07-21 14:09
    关注

    I would start the file creation via ajax (call generate.php), display a message to the client "your file is being generated, and will download when ready. Please do not close your browser".

    In generate.php, when done set some kind of flag, eg update a database, save a file to disk etc.

    After the initial ajax to generate.php, periodically (say every 30 seconds) make an ajax request to check.php, which checks for the flag mentioned above.

    If found, the file uri is returned to the calling js, which can then download it (set window.location, or src of a hidden iframe)

    评论

报告相同问题?

悬赏问题

  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值