Giter Club home page Giter Club logo

Comments (11)

albertcht avatar albertcht commented on May 18, 2024 4

Try add db to instances or add Illuminate\Database\DatabaseServiceProvider::class to providers in config/swoole_http.php.

from laravel-swoole.

megawubs avatar megawubs commented on May 18, 2024 1

It works! thank you!

from laravel-swoole.

albertcht avatar albertcht commented on May 18, 2024

Hi @megawubs ,

Is you code in the same request?

from laravel-swoole.

megawubs avatar megawubs commented on May 18, 2024

Yes, it's being preformed in a middleware

from laravel-swoole.

albertcht avatar albertcht commented on May 18, 2024

Hi @megawubs ,

Where did you define your $config ? How about using config()->set('foo', 'bar') and see if config changes by config('foo')?

from laravel-swoole.

megawubs avatar megawubs commented on May 18, 2024

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...

from laravel-swoole.

albertcht avatar albertcht commented on May 18, 2024

Hi @megawubs ,

Does this middleware work in the traditionally FPM?

from laravel-swoole.

megawubs avatar megawubs commented on May 18, 2024

Yes

from laravel-swoole.

megawubs avatar megawubs commented on May 18, 2024

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)

from laravel-swoole.

albertcht avatar albertcht commented on May 18, 2024

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.

from laravel-swoole.

megawubs avatar megawubs commented on May 18, 2024

from laravel-swoole.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.