0

I have a resumable download php script.

It works fine on Apache server but not on IIS 7 ( which my client currently use)

The problem with IIS is:

When downloading file,other page at same site will freeze. (even display 500 server error sometimes) (same script on a Apache server does not carry the same problem)

The problem disappared if I turnoff resumable support (even downloading on a download manager will freeze all browsers viewing the same site)

This make me believe IIS need some configuration? or php.ini?

I have no luck with google so far any help will be grateful and.. yes, I have access on IIS and php.ini and yes..I setup the maximum connection time on IIS already(needed for large file transfer)

this script is.. (anybody come across here and like to use this script for large file tranfer on IIS please read -->php on IIS 7 >> FastCGI timeout settings<< )

$filename="test.flv";
$filepath="zekkai.flv"; 
//set mime
 $mime_type="";
 $known_mime_types=array(
    "flv" => "video/x-flv",
    "mp4" => "video/mp4",
    "mov" => "video/quicktime",
    "avi" => "video/x-msvideo",
    "wmv" => " video/x-ms-wmv "
 );
 if($mime_type==''){
     $file_extension = strtolower(substr(strrchr($filepath,"."),1));
     if(array_key_exists($file_extension, $known_mime_types)){
        $mime_type=$known_mime_types[$file_extension];
     } else {
        $mime_type="application/force-download";
     };
 };
header("Connection: Keep-Alive"); 
header("Keep-Alive: timeout=65000"); 
$fsize=filesize($filepath);
set_time_limit(0);
//turn off buffer
ob_end_clean();
if(ini_get('zlib.output_compression'))
ini_set('zlib.output_compression', 'Off');
header("Content-Description: File Transfer");
header("Content-type: ".$mime_type);
header("Content-Disposition: attachment; filename=\"".$filename."\"");
header("Content-Transfer-Encoding: binary");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header('Accept-Ranges: bytes');
header("Cache-control: public");
header('Pragma: public');
header("Expires: 0");
// resumable support..
if(isset($_SERVER['HTTP_RANGE'])){
                 // delete this part to turnoff resumable support 
    list($a, $range) = explode("=",$_SERVER['HTTP_RANGE'],2);
    list($range) = explode(",",$range,2);
    list($range, $range_end) = explode("-", $range);
    $range=intval($range);
    if(!$range_end) {
        $range_end=$fsize-1;
    } else {
        $range_end=intval($range_end);
    }
    $new_length = $range_end-$range+1;
    header("HTTP/1.1 206 Partial Content");
    header("Content-Length: $new_length");
    header("Content-Range: bytes $range-$range_end/$fsize");
                // resumable support end 
} else {
    $new_length=$fsize;
    header("Content-Length: ".$fsize);
}

/* output the file itself */
 $chunksize = 3*(1024*1024); //you may want to change this
 $bytes_send = 0;
 if ($Source_File = fopen($filepath, 'rb')){
    if(isset($_SERVER['HTTP_RANGE'])){
        fseek($Source_File, $range);
    }
    while(!feof($Source_File) && (!connection_aborted()) && ($bytes_send<$new_length) ) {
        $buffer = fread($Source_File, $chunksize);
        print($buffer); //echo($buffer); // is also possible
        flush();
        $bytes_send += strlen($buffer);
    }
    fclose($Source_File);
 } else die('Error - can not open file.');
exit();
Artjom B.
  • 61,146
  • 24
  • 125
  • 222
Yuan Shen
  • 79
  • 1
  • 3

1 Answers1

0

note. none php script is not affected. only php page affect by the download.. so my guess the problem is realted to fastcgi module?

Yuan Shen
  • 79
  • 1
  • 3
  • Is this supposed to be an answer? If not then please remove it and add the information to your question. If yes, please clarify by editing your answer. – Artjom B. Nov 30 '14 at 13:35