Hi,

I have a script that writes a cookie on a user's machine before returning a (large) file to download.

The current version looks like this:

<?php
setcookie('cookie', 'value', time() + 315360000, '/', '.mydomain.com', 0);

header("Location: [url]http://www.mydomain.com/file.exe[/url]");
exit;

?>

This works great but I would like to avoid the browser roundtrip created by the redirect.

I know that I can use the readfile function but since the files I am returning are very large I do not want the php engine to be running all that time for a single download, nor the engine to timeout.

Do you have any suggestion on how to handle this? (my web server is Apache.)

Thanks,

/phil

    i dont think php will be running for very long. reading the file from disk is fast. php will read the file into its output buffer and hand it to apache as soon as its done. even if it takes the user a few min to download it php wont be sitting there waiting for it to finish, apache will, and since apache is the webserver, i think thats what you want 🙂

      Thank you rehfeld.

      Do you know where I could find more information about this so I can make sure it is the case?

        Write a Reply...