Please answer these questions before submitting your issue. Thanks!
php -v and php --ri swoole)swoole
swoole support => enabled
Version => 1.10.5
Author => tianfeng.han[email: [email protected]]
kqueue => enabled
rwlock => enabled
async http/websocket client => enabled
pcre => enabled
zlib => enabled
Directive => Local Value => Master Value
swoole.aio_thread_num => 2 => 2
swoole.display_errors => On => On
swoole.use_namespace => Off => Off
swoole.fast_serialize => Off => Off
swoole.unixsock_buffer_size => 8388608 => 8388608
Please provide your Laravel/Lumen version.
Laravel v5.5.40
Which release version of this package are you using?
v2.3.8
What did you do? If possible, provide a recipe for reproducing the error.
$db = app('db');
$db->purge('mysql_database_1');
$db->purge('mysql_database_2');
$config->set('database.connections.mysql_database_1.database', 'database_5');
$config->set('database.connections.mysql_database_2.database', 'database_6');
$db->reconnect('mysql_database_1');
$db->reconnect('mysql_database_2');
What did you expect to see?
my newly configured database to be used.
What did you see instead?
The old config is still used when recreating the database connection.
Hi @megawubs ,
Is you code in the same request?
Yes, it's being preformed in a middleware
Hi @megawubs ,
Where did you define your $config ? How about using config()->set('foo', 'bar') and see if config changes by config('foo')?
ah, i see i missed that part from copy pasting.
The full code is:
$config = app('config');
$db = app('db');
$db->purge('mysql_database_1');
$db->purge('mysql_database_2');
$config->set('database.connections.mysql_database_1.database', 'database_5');
$config->set('database.connections.mysql_database_2.database', 'database_6');
$db->reconnect('mysql_database_1');
$db->reconnect('mysql_database_2');
i've tried it with different ways of resolving the config. That's not the problem. When i read out the config later, it is changed. Only, the database connection is not...
Hi @megawubs ,
Does this middleware work in the traditionally FPM?
Yes
Try add db to instances or add Illuminate\Database\DatabaseServiceProvider::class to providers in config/swoole_http.php.
Your tip to add db to the instances field helps a bit. But only for DB::* calls, not for eloquent calls.
I've created a test application to be able to isolate the problem. You can see it here: https://github.com/megawubs/swoole-debug
The steps to reproduce are located in the readme.
When i add this: \Log::info('the connection is: ', (array)$this->connection); on line 2588 in Illuminate\Database\Query\Builder you can see that the connection does not change when using eloquent. (route /1)
Hi @megawubs ,
I didn't clone your repo yet, but I think it is caused by Illuminate\Database\Eloquent\Model::class. There are lots of statics in this model class. ConnectionResolver is also called by static and it's only set once in service provider. This may cause static variable pollutions.
Did you try to add Illuminate\Database\DatabaseServiceProvider::class to providers in config/swoole_http.php? Not sure if it helps.
I'll try that, thanks
Verstuurd vanaf mijn iPhone
Op 25 mei 2018 om 5:16 PM heeft Albert Chen notifications@github.com het volgende geschreven:
Hi @megawubs ,
I didn't clone your repo yet, but I think it is caused by Illuminate\Database\Eloquent\Model::class. There are lots of statics in this model class. ConnectionResolver is also called by static and it's only set once in service provider. This may cause static variable pollutions.
Did you try to add Illuminate\Database\DatabaseServiceProvider::class to providers in config/swoole_http.php? Not sure if it helps.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
It works! thank you!
Most helpful comment
Try add
dbtoinstancesor addIlluminate\Database\DatabaseServiceProvider::classtoprovidersinconfig/swoole_http.php.