Yii Cdbhttpsession Not Deleting Expired Data

We are using CDbHttpSession for sessions, but today when we checked the table it had results which had expiry time of Dec. 2012, that means it is not deleting the expired data…

Is it an expected behavior, It is for sure slowing down the site as the table now has 2M records, out of which 1.9 M are of < expiry date…

So what is that we are doing wrong, any suggestions??

Set up a cron job to clean up old records. You may use a CConsoleCommand to do so, eg:

class SessionCommand extends CConsoleCommand


	public function actionCleanUp()


		Yii::app()->db->createCommand("DELETE FROM yiisession WHERE expire > UNIX_TIMESTAMP()")->execute();



Then add an entry like this one to your crontab:

0 0 * * * /path/to/yii/protected/yiic session cleanUp

Obviously use proper path… The above will run at midnight every day.

Garbage Collector has a 1% percent of chance for each request by default. Try using 50% or so.