I am building a selenium test suite which pulls a list of tests to run and then forks those tests to multiple parallel processes. Each process needs its own connection to the database because of two reasons: one, when the child process ends the connection is closed and two, when you have several processes sharing a connection and all running queries at the same time, sometimes mysql can generate some strange errors. The problem that I am running into is that since each process is going to need its own connection, I am worried about running out of connections. Is there a way to have PDO wait for an avaialbe connection if max connections is hit?

Recommended Answers

All 3 Replies

I suppose I could just do a loop with a nested try catch with a sleep. Unless there are more elegant ideas I guess I'll go with that.

another thoughts..

you can also count the PROCESSLIST to find out if you are on the max connection allowed , then let the next connection to sleep, check on wake up and then sleep if there is not available slot, else let the processes to continue. 150 is a lot of connections already, but I have seen people have it set to more than 4000.

The safest and most elegant ways of doing this is probably increasing the max_connections value to some desired number, but reasonably fair to the database server to handle.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.