giorgio
giorgio

Reputation: 11

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

Upvotes: 1

Views: 549

Answers (3)

Petr Svec
Petr Svec

Reputation: 11

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

Upvotes: 1

dnagirl
dnagirl

Reputation: 20446

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.

Upvotes: 0

Pekka
Pekka

Reputation: 449613

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?

Upvotes: 2

Related Questions