swooletw / laravel-swoole

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

How app() will work? #477

Closed evsign closed 3 years ago

evsign commented 3 years ago

Could you please explain how laravel helper app(...) would work? In doc and in some issues i've seen how has been said that using facades is safe and each request will be bound to the separate container instance, but i don't understand how it will work safely with app(...) function.

Currently laravel app(...) function looks like this:

function app($make = null, array $parameters = [])
{
    if (is_null($make)) {
        return Container::getInstance();
    }

    return Container::getInstance()->make($make, $parameters);
}

and Containe::getInstance():

public static function getInstance()
{
    if (is_null(static::$instance)) {
        static::$instance = new static;
    }

    return static::$instance;
}

As i see he stores himself in global static property which could be overwritten if some of request start concurrency io work. Swoole will pause one coroutine and start another where new request can come and container instance will be reseted.

evsign commented 3 years ago

Also maybe it's related to https://github.com/swooletw/laravel-swoole/issues/395

Arkanius commented 3 years ago

Hi there,

swoole "rebinds" the app container instance at each request. The app is a default rebinding. You can see other cleanings, resets and rebinds at config file.

evsign commented 3 years ago

Worker is not asynchronous?

Arkanius commented 3 years ago

Yes, but each request has his own container binded