bcosca / fatfree

A powerful yet easy-to-use PHP micro-framework designed to help you build dynamic and robust Web applications - fast!
2.66k stars 446 forks source link

avoid useless database connections #1265

Closed sbraaa closed 1 year ago

sbraaa commented 1 year ago

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?

ikkez commented 1 year ago

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.

sbraaa commented 1 year ago

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