900 MB of forced downloads rarely end

I tried all the headers. With and without content.

The problem is that dowload is halfway through. But only in most cases.

Sometimes it works fine.

Using a server resource is trivial. All configuration files are in order. I do not run php script while it is on.

Has anyone seen this before? Isn't that my fault? Why sometimes?

$file = "http://domain.com/files/".$item_number.".mov"; header( 'Pragma: no-cache' ); header( 'Cache-Control: must-revalidate, post-check=0, pre-check=0' ); header( 'Content-Description: File Download' ); header( 'Content-Type: application/force-download'); //header ('Content-Type: video/quicktime');//doesnt seem to download at all here header( 'Content-Length: '.filesize( $file ) ); header( 'Content-Disposition: attachment; filename="'.basename( $file ).'"' ); header( 'Content-Transfer-Encoding: binary' ); readfile( $file ); exit(); 

Thank you, Sorry, but for the first time.

+6
source share
1 answer

This may have several reasons.

You say server resources are fine, but I think PHPs readfile() loads the entire file into memory before sending it. Fortunately, there is a good solution in the documents that you should definitely use to prevent problems with multiple downloads :)

Also, have you set the script execution time to infinite?

Next will be the settings of your server. Perhaps they close the connection for some timeout / resource reason.

Use the Google Chromes Developer Tool to carefully review the headers you sent. PHP sets some headers on its own. You should put session_cache_limiter(false); to the beginning of your script. If I remember correctly, even Expires: Thu, 19 Nov 1981 08:52:00 GMT ... Why is this bad? Next up;)

You can send Etag and Last-Modified header. I summarize this unique identifier for your resource, which allows you to resume downloading. I think finding good articles about this is better than just giving you some suggestions. In your case, you can use PHPs stat() to create Etag.

There are some people struggling with headers and downloads, you can start (or fix your case) here

Summary:

  • Check PHP expiration settings / server / limits / resources
  • Be sure to send the buffered file
  • Let me resume downloading
  • Check sent headers.

After that you should be fine. With renewal, even if it breaks anyway ...

Good progress and success!

+3
source

Source: https://habr.com/ru/post/917922/


All Articles