Serving files without

Hi,

I am trying to cache and serve image files from a DB, transparently, using Yii. I am using the url manager to do that, which works quite nicely:




	        'urlManager'=>array(

        		'urlFormat'=>'path',

			'showScriptName'=>false,

        		'rules'=>array(

				'/images/<name>.jpg'=>'site/image',

        		),

        	),



In my SiteController I have something like the code below:




	public function actionImage($name)

	{

		// load file from DB, caches on file system, set its path and modification time

		$path= ...;

		$mtime=...;


		header('Content-Type: image/jpeg');

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

		header('Last-Modified: '.gmdate('D, d M Y H:i:s',$mtime).' GMT');

		header_remove('Expires');

		header_remove('Cache-Control');

		header_remove('Pragma');


		echo file_get_contents($path);

	}



However, I am facing a huge performance penalty, and it is due to sessions/user authentication. I am using DB sessions, and accessing the DB to read user session data does take much more time than reading from the local file system.

Since the behavior I am trying to achieve is similar to static serving files, it does not depend on session information. Is there a way to configure Yii to by-pass all the session/authentication handling code when performing this action?

Thanks!

Did you protect this method from guest access maybe? Sessions are usually only opened when certain properties of the user object are accessed (like Yii::app()->user->isGuest). And of course, whenever you access the session directly from code.

I realized the problem.

I use a control filter to enforce RBAC to other actions of the SiteController, so I moved the actionImage method to a plain unfiltered controller, and it worked!

Thanks a lot for the insight Mike!