开发者

Delay inbetween two simultaneos php file downloads from the same script

I have a strange problem here: If I try to download more than one file with the same download script (I've tried 5 different scripts found on php.net), the first goes well but the second has a delay of about 60 seconds from th开发者_如何转开发e time of its request. If I cancel the first download, then the second starts suddenly. I've tested direct file download from apache and everything is ok. This is the last script I've tried:

<?php
$filename= $_GET['file'];

header("Content-Length: " . filesize($filename));
header('Content-Type: application/zip');
header('Content-Disposition: attachment; filename=writeToFile.zip');

$file_contents = file_get_contents($filename);
print($file_contents);
?>


Could it be that the underlying web server has a limit on concurrent connections from the same IP? Can you try from two different IPs at the same time?


no, no no... problem is somewhere else

you have started session (manualy or automatically) and session are usually stored in files...

so when open first script then open session and LOCK FILE ... other request must wait for unlocking session file...

existing two solution... - use self class for session storing ... without locking of file session (bug scripts may overwrite sessions data) - or before file_get_content call session_write_close();


You might try readfile($filename) instead of $file_contents = file_get_contents($filename);print($file_contents); Since readfile() doesn't store the contents in a string, it doesn't take up memory the way file_get_contents() does.

@Pekka Gaiser has a good point about concurrent connections. Also take a look at what kind of memory limits your PHP is using.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜