Too Many Connections

Hi ,

in one of my project , when traffic is reaching to much i am getting CDbException

CDbConnection failed to open the DB connection.

and in my logs is this:

SQLSTATE[HY000] [1040] Too many connections

what is the solution for that?

increase database connections limit or reduce allowed php processes… you could also consider using some pooling mechanizm in the middle (working as a proxy between php and database). You should also avoid persistent connections as they keep connections (the cost will be the speed, because persistent connections do not have overhead of establishing connection on every request)

For rerference: You need to raise the max_connections server variable. While you’re at it, you might want to alter the thread_cache_size var as well.

thanks for your advise,

i am using CDbHttpSession class for handling my sessions and when i checked the online proccess of query in Database Server, most off them it was for YiiSession Table (almost 90%),

maybe this is a problem??

What database are you using?

Some settings can be influenced at client-session level, some can not - everything depends on your RDBMS setup.

See initSQLs.

maybe you store too much data in session? Also make sure there is primary key/unique index on session id column.

I have experience with very large site using Yii and sessions in db and there are no problems with that.