-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Yii2 - Functional testing - Too many connections #1363
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Are you using persistent connections? |
Im running a local Xampp machine with nearly default settings. ; Allow or prevent persistent links. ; If mysqlnd is used: Number of cache slots for the internal result set cache ; Maximum number of persistent links. -1 means no limit. ; Maximum number of links (persistent + non-persistent). -1 means no limit. |
it looks like a DB connection is created for every call in the testsuites. In a browser, manually F5-ing a page with db-queries works normally with only 1 thead. |
In case of functional tests we're basically running an application the same way as we're doing it normally. The only difference (that actually isn't really a difference in case of high traffic projects) is that query frequency is quite high. I'm not sure why PHP isn't reusing connections and creating new ones but it's not something Yii or Codeception controls so could not be fixed from Yii or Codeception side. |
@samdark, the problem seems to be solved when applying the PDO attribute to the Yii2 + DB config. The solution, use: 'db' => array(
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=yii2_advanced_test',
'username' => 'root',
'password' => '',
'tablePrefix' => '',
'charset' => 'utf8',
'attributes'=>[
PDO::ATTR_PERSISTENT => true
]
), |
It's quite rare to configure MySQL persistent connections with php.ini and it seems you've found a conflict between PDO and mysqlnd. Not sure we should describe such a rare PHP and MySQL issue in the Yii guide. |
I had the exact same problem and adding
helped me. |
I had the same problem on the unit (integration) tests and adding PDO::ATTR_PERSISTENT => true to my config worked too! |
@anders-akero thank you so much, this helped me |
I ran into the same issue today - setting the persistent attribute solved it beautifully. Thank you!!! |
Im getting an explosion of db-connections when running functional tests with Yii2. If the test sequence is long enough, it will reach its maximum allowed connections.
Is this normal behavior?
The text was updated successfully, but these errors were encountered: