bcosca / fatfree

A powerful yet easy-to-use PHP micro-framework designed to help you build dynamic and robust Web applications - fast!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

avoid useless database connections

sbraaa opened this issue · comments

Typically in my webapps I store frequently used data in cache storage engine (memcached, redis, ..) to reduce database queries.
I made a PDO wrapper to instantiate a db connection only if I need to do a query, so if all page data are available in cache storage engine I virtually cannot connect to the database at all (I made this to avoid MySQL “Too many connections” error).

I would like to use \DB\SQL in my models classes but how can I prevent useless db connections?
I mean, to create a new instance I need to provide database connection data so it could happen that I create a database connection even if I dont need to query any data.
Any ideas?

How and when are you initializing a DB connection? Only once per request and not per usage I hope.
This kind of question is better placed in our google board or in our matrix chat. Please come and join us there for discussions.
One idea though might be to just wrap the DB\SQL class, wrap the PDO class and make it lazy initializing the real connection via proxy and use your custom PDO in your custom DB\SQL and use this for your mappers.

Ok @ikkez , I'll join F3 google board to discuss there about this, thank you