PHP脚本在打印/刷新语句期间会发生超时吗?
我有一个下载脚本,它会检查一些内容,然后以 8kb 的块的形式传输文件。
进行传输的循环如下所示:
$file = @fopen($file_path,"rb");
if ($file) {
while(!feof($file)) {
set_time_limit(60);
print(fread($file, 1024*8));
flush();
if (connection_status()!=0) {
@fclose($file);
die();
}
}
@fclose($file);
}
我编写了一个小应用程序,它模拟了非常慢的下载。等待 2 分钟,然后继续下载。鉴于我设置了 60 秒的时间限制,我预计脚本会超时。这种情况不会发生,下载将继续直至完成。看来打印/刷新所花费的时间不计入脚本执行时间。这是正确的吗?有没有更好的方法将文件发送到客户端/浏览器,以便我可以指定打印/刷新命令的时间限制?
I've got a download script which checks a couple of things and then streams a file across in chunks of 8kb.
The loop that does the transfer looks like:
$file = @fopen($file_path,"rb");
if ($file) {
while(!feof($file)) {
set_time_limit(60);
print(fread($file, 1024*8));
flush();
if (connection_status()!=0) {
@fclose($file);
die();
}
}
@fclose($file);
}
I wrote a small application which simulated a very slow download. It waits for 2 minutes before continuing the download. I expected that the script would time out given that I've set a 60 second time limit. This does not happen and the download continues until it has finished. It seems that the time spent in print / flush doesn't count towards the script execution time. Is this correct? Is there a better way to send the file to the client / browser such that I can specify a time limit for the print / flush command?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
来自
set_time_limit()
:所以看起来你可以测量通过调用
time()
函数来实时传递,大致如下:或者您可以使用 Windows。我更喜欢第一个选项:p
From
set_time_limit()
:So it looks like you can either measure the passage of real time with calls to the
time()
function, along the lines of:Or you can use Windows. I prefer the first option :p