swooletw / laravel-swoole

High performance HTTP server based on Swoole. Speed up your Laravel or Lumen applications.
MIT License
4.04k stars 389 forks source link

New database connection(s) getting created for each request #370

Closed harishdurga closed 4 years ago

harishdurga commented 4 years ago
  1. Please provide your PHP and Swoole version. (php -v and php --ri swoole) PHP 7.2.26-1+ubuntu18.04.1+deb.sury.org+1 and swoole version 4.4.14

  2. Please provide your Laravel/Lumen version. Laravel 5.8

  3. Which release version of this package are you using? 2.6.66

  4. What did you do? If possible, provide a recipe for reproducing the error. I have added Illuminate\Database\DatabaseServiceProvider::class to the providers array. After this every request is creating a new client connection to the database.

  5. What did you expect to see? Connection reuse, or connections getting closed automatically once the request is completed.

  6. What did you see instead? Each request is creating new database connection(s) and old connections are still there. I can see lot of connections for the Mysql server from the work bench.If i comment this Illuminate\Database\DatabaseServiceProvider::class then the issue is not present. My requirement is to connect to different databases based on the request parameters.

codercms commented 4 years ago

If you want to reuse existing connections you shouldn't add DatabaseServiceProvider to the "providers" section. For your case I recommend to configure a multiple database connections in the config/database.php file and choose needed connection from the application layer.