Need Help To Solve Issue When Large File Download

Hi friends I am working file based project in our company. When i download using below code, The model did not affect at end of download But file downloaded successfully. Ex 300Mb file take 1 hour 30 mins in client system. If i used wrong method to download the file, Please give me some idea.




                        $downloadlog=new Downloadlog;

                        $downloadlog->userid=$userid;

                        $downloadlog->documentid=$id;

                        $downloadlog->createdon=new CDbExpression('NOW()'); 

                        $ctype="application/zip";

                        header("Pragma: public");

                        header("Content-Type: $ctype");

                        header("Cache-Control: public");

                        header("Content-Description: File Transfer");

                        header("Content-Disposition: attachment; filename=\"".basename($zippath)."\";");

                        header('Content-Length: '.filesize($zippath));

                        header("Content-Transfer-Encoding: binary");

                        header("Expires: 0"); 

                        header("Cache-Control: must-revalidate, post-check=0, pre-check=0");

                        ob_clean();

                        flush();

                        readfile( $zippath);

                        unlink($zippath);

                        $downloadlog->save();



Thanks




if(!$downloadlog->save()) {

    print_r($downloadlog->getErrors());

    exit;

}



Any output?

You model cannot be affected, since PHP will stop executing scripts after 30 secs (by default). File still can be succesfully streamed down. Your options:

  • Just change workflow - first update the model, then do download.

  • Or you can try to set PHP environmental variable "max_execution_time" to something like 7200 (= 2 hours)

  • or use function "set_time_limit(0)" - see http://php.net/manual/en/function.set-time-limit.php.

I would go for first option - changing the order of execution.

Thanks lubosdz. I applied first option