Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Closed
dynasource opened this issue Aug 30, 2014 · 10 comments
Closed

Yii2 - Functional testing - Too many connections #1363

dynasource opened this issue Aug 30, 2014 · 10 comments

Comments

@dynasource
Copy link
Contributor

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?

@dynasource dynasource changed the title Yii2 - Too many connections Yii2 - Functional testing - Too many connections Aug 30, 2014
@samdark samdark added the yii label Aug 30, 2014
@samdark
Copy link
Member

samdark commented Aug 30, 2014

Are you using persistent connections?

@dynasource
Copy link
Contributor Author

Im running a local Xampp machine with nearly default settings.

; Allow or prevent persistent links.
; http://php.net/mysql.allow-persistent
mysql.allow_persistent=On

; If mysqlnd is used: Number of cache slots for the internal result set cache
; http://php.net/mysql.cache_size
mysql.cache_size=2000

; Maximum number of persistent links. -1 means no limit.
; http://php.net/mysql.max-persistent
mysql.max_persistent=-1

; Maximum number of links (persistent + non-persistent). -1 means no limit.
; http://php.net/mysql.max-links
mysql.max_links=-1

@dynasource
Copy link
Contributor Author

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.

@samdark
Copy link
Member

samdark commented Aug 30, 2014

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 samdark closed this as completed Aug 30, 2014
@dynasource
Copy link
Contributor Author

@samdark, the problem seems to be solved when applying the PDO attribute to the Yii2 + DB config.
I guess this is something for the manual.

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
            ]

        ),

@samdark
Copy link
Member

samdark commented Aug 31, 2014

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.

@anders-akero
Copy link

I had the exact same problem and adding

            'attributes'=>[
                PDO::ATTR_PERSISTENT => true
            ]

helped me.

@adamdry
Copy link

adamdry commented Sep 21, 2015

I had the same problem on the unit (integration) tests and adding PDO::ATTR_PERSISTENT => true to my config worked too!

@hmphu
Copy link

hmphu commented Jan 20, 2016

@anders-akero thank you so much, this helped me

@DanaLuther
Copy link

I ran into the same issue today - setting the persistent attribute solved it beautifully. Thank you!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants