views:

120

answers:

3

Hi, 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 the 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);
?>
+2  A: 

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?

Pekka
A: 

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.

dnagirl
+1  A: 

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();

Petr Svec