sendFile unexpected behaviour with logging on


I encountered an unexpected behaviour when using sendFile to provide a download link for the users. I have the following (simplified) code in one of my controllers:

public function actionDownload()


   $file = 'serverFile.pdf';



      return Yii::app()->getRequest()->sendFile('myfile.pdf', @file_get_contents($file));



Now this code works well if the logging is desactivated. When I do this on my test version with logging on, the downloaded file has the right size, but is corrupted. If the logging is on, the first part of the file contains the logging information, and then only the actual pdf content (which is then truncated due to the size of the file).

Am I doing something wrong with the sendFile method or is this the expected behaviour?

I’m using yii 1.1.6.

Thanks for your help.



Just reported this issue as bug, and got following answer:

Comment by project member qiang.xue:

You need to disable the web log route in this case.

Note that the sendFile() call is not aware of any further output modification, nor CWebLogRoute is aware that the current request is file downloading.

In case it helps, here is a function I use to do this. I’m pretty new to Yii, so there’s probably a smarter way, but this does get the job done.

  public static function disableCWebLogRoute() {

        $logRouter = Yii::app()->getComponent("log");

        if (isset($logRouter)) {

            $routes = $logRouter->getRoutes();

            foreach ($routes as $route) {

                if ($route instanceof CWebLogRoute) {

                    $route->enabled = false;