Cache & DB Connection Fallback

Is there a way to make my application gracefully fallback if my memcache and/or DB connection fails when the page loads initially?

It seems like if you add the DB/Memcache info into your site configuration and either doesn’t work the page just craps out saying it couldn’t connect to the DB/Cache.

I’d like the system to just bypass the caching procedures (e.g. all caching sets/gets fail or return false) in the event that a connection to the caching server can’t be established. The cache isn’t 100% needed but obviously it helps speed things up a lot.

If the DB connection fails then it’d be nice to do the same sort of thing as above. If the DB is down for a little bit pages could still potentially work given that the caching server is still operational.

It just seems a bit short sighted to terminate the app like Yii does if either of the predefined connections don’t work.

Is there any way to get around this?

Any help is greatly appreciated.


You could add your custom dependency check logic to your base controllers init() method. Then use Yii::app()->setComponent(null) to disable any component if you think your app can still run without.

Not tested…