Page 1 of 1

Download delay with Internet Explorer

Posted: Fri Feb 01, 2008 9:15 am
by lostjohnny
Hi.

I have a php script that downloads a file (an executable as it happens) to the client's computer. I list the script is at the end of this message.

When I connect with Internet Explorer, there is a random long delay before I am asked where to save the file. I've measured this delay as 2 mins 40, over 3 mins and once I gave up after 7 mins (don't know if that one was ever going to download the thing).

If I use Firefox as the client, the file downloads in an instant, as it should as it's 400KB and I'm testing on a LAN.

Whichever client I use, the file is present and correct once it's apparantly downloaded.

My server runs Linux, Apache and PHP.

The file to download is in a separate part of the file system to /var/www. It's actually in /usr/share/downloads/

The script to download the file (called DownloadGizzyWatch.php) is invoked when the user clicks on this link in another file:

Code: Select all

<a href="DownloadGizzyWatch.php">Download GizzyWatch</a>
I only want the file to be accessible to logged in users. Am I going about it in the right way?

TAI,

Lost Johnny.

DownloadGizzyWatch.php....

Code: Select all

<?php
 
include 'addresses.inc.php';
 
function _Download($f_location,$f_name){
  //  header ("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  header('Content-Description: File Transfer');
  header('Content-Type: application/octet-stream');
  header('Content-Length: ' . filesize($f_location));
  header('Content-Disposition: attachment; filename=' . basename($f_name));
  readfile($f_location);
}
 
{
 
  session_cache_limiter('none'); //*Use before session_start()
  session_start();
 
  if (!session_is_registered("svUsername")
      || !isset($_SESSION["svUsername"])
      || empty($_SESSION["svUsername"])){
    header("Location: http://" . $ServerAddress . "/arrivedinerror.html");
    exit;
  }
 
 
  $file = 'GizzyWatch.exe';
 
 
  _Download( "/usr/share/downloads/" . $file, $file);
}
 
?>

Re: Download delay with Internet Explorer

Posted: Sat Feb 02, 2008 5:47 am
by lostjohnny
Further information...

The site uses SSL. I haven't bought a certificate yet (it's only a test site on a broadband connection) so the user has to choose to proceed despite the certification error.

I've tried various calls to session_cache_limiter() and no call to it at all.

Code: Select all

 //session_cache_limiter("must-revalidate"); //*Use before session_start()
  //session_cache_limiter('public');
  //session_cache_limiter('none');

I've followed the advice in this article http://www.extremetech.com/article2/0,1697,20373,00.asp and added ssl-unclean-shutdown to
BrowserMatch "MSIE 4\.0b2;"
I also changed this to read
BrowserMatch "MSIE*"

There is still the long delay before the file downloads, if it downloads at all.

Re: Download delay with Internet Explorer

Posted: Sat Feb 02, 2008 10:12 am
by andym01480
IE is a bit of a pain when it comes to download headers! Seems a lot fussier than firefox.

Try it with out the Content-description header

This worked for me

Code: Select all

header ("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/$q");
header("Content-Disposition: attachment; filename=$file");
header("Content-Transfer-Encoding: binary");
readfile("../$file");
where $q was the type.

You could use

Code: Select all

mime_content_type  ( $filename  )
to make sure the Content-Type header is correct as well

Re: Download delay with Internet Explorer

Posted: Sat Feb 02, 2008 1:46 pm
by lostjohnny
Thanks for the suggestion, andym01480.

I've taken your code and adjusted it for my needs. I've also simplified the code a bit, getting rid of the function etc. (it was code I copied from somewhere else).

I also tried using mime_content_type, but it just seemed to think the file was text and causing a ".txt" extension to be added when it was downloaded, so I went back to manually specifying application/octet-stream.

My code is now.

Code: Select all

<?php
 
include 'addresses.inc.php';
 
session_cache_limiter("must-revalidate"); //*Use before session_start()
//session_cache_limiter('public');
//session_cache_limiter('none');
session_start();
 
if (!session_is_registered("svUsername")
    || !isset($_SESSION["svUsername"])
    || empty($_SESSION["svUsername"])){
  header("Location: http://" . $ServerAddress . "/arrivedinerror.html");
  exit;
 }
 
header ("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=GizzyWatch.exe");
header("Content-Transfer-Encoding: binary");
readfile("/usr/share/downloads/GizzyWatch.exe");
?>
Same result - the file (usually) downloads successfully after a long pause of about 3 minutes with IE as the client - downloads successfully and immediately with Firefox.

Re: Download delay with Internet Explorer

Posted: Sat Feb 02, 2008 2:57 pm
by andym01480
Try getting rid of

Code: Select all

session_cache_limiter("must-revalidate"); //*Use before session_start()
and changing the 1st two headers to

Code: Select all

header("Cache-Control: public, must-revalidate");
header("Pragma: public");
see http://uk.php.net/manual/en/function.header.php#74736

I've read IE doesn't like post-check=0, pre-check=0

Lots of people have posted diff hacks on http://uk.php.net/manual/en/function.header.php so you may find something else that works!

Re: Download delay with Internet Explorer

Posted: Mon Feb 04, 2008 8:44 am
by lostjohnny
Got it working!

I pretty much use the code given in this article:
http://uk.php.net/manual/en/function.header.php#74884

I think it's the line

Code: Select all

header("Pragma: hack");
that does the trick. Says it all really.