Coder Social home page Coder Social logo

Comments (17)

terranc avatar terranc commented on May 3, 2024 5

@PeteLuo 我最后还是换成https://github.com/swooletw/laravel-swoole来解决的,不过貌似它们也是有需要配置重新注册的provider,最后我的配置是:

        Illuminate\Auth\AuthServiceProvider::class,
        App\Providers\AuthServiceProvider::class,
        Tymon\JWTAuth\Providers\LaravelServiceProvider::class,

你可以在laravel-s里尝试一下把这些都重新注册下

from laravel-s.

flymorn avatar flymorn commented on May 3, 2024 1

解决方法:
第一步:config/laravels.php

'register_providers' => [
        // 重载auth相关服务
        \Illuminate\Auth\AuthServiceProvider::class,
        \App\Providers\AuthServiceProvider::class,
        \Tymon\JWTAuth\Providers\LaravelServiceProvider::class,
    ]

第二步,建立全局中间件 EveryRequest.php

public function handle($request, Closure $next)
    {
        // swoole请求进来的时候删掉缓存
        if (PHP_SAPI == 'cli') {
            \Illuminate\Support\Facades\Facade::clearResolvedInstance('auth');// swoole下解决auth单例问题
        }

        return $next($request);
    }

以上2步缺一不可

from laravel-s.

igo9go avatar igo9go commented on May 3, 2024

使用jwt,二个用户同时请求这个返回结果都一样了,二个人的信息是不一样的

from laravel-s.

hhxsv5 avatar hhxsv5 commented on May 3, 2024

@igo9go 在配置中重新注册下ServiceProvider即可,here

from laravel-s.

PeteLuo avatar PeteLuo commented on May 3, 2024

我使用jwt也是有同样问题,两个用户同时请求两个人的信息就会变成一样的,register_providers已经添加了JWT的JWTAuthServiceProvider。
image

系统环境:Ubuntu16.04
JWT:"tymon/jwt-auth": "^0.5.12"
laravel-s:"hhxsv5/laravel-s": "~3.0"

from laravel-s.

Barbery avatar Barbery commented on May 3, 2024

上线前手贱升级了laravels的版本,发现最新的V3.1.0设置了register_provider还是不行,auth实例还是被cache起来了,没有被清除掉。配置不变,换回V2.0.7又一切正常。 @hhxsv5

from laravel-s.

Barbery avatar Barbery commented on May 3, 2024

已解决该问题,说下我的方法:
auth的对象没有释放的问题,对比了下代码和调试,似乎新版本是https://github.com/hhxsv5/laravel-s/blob/v2.0.7/src/Illuminate/Laravel.php#L152 这里没了Facade::clearResolvedInstance auth这个对象,我监听了laravels.received_request事件后,手动clear auth对象就正常了

from laravel-s.

hhxsv5 avatar hhxsv5 commented on May 3, 2024

根本原因还是单例问题

方案:

  • 重新注册Provider:
# config/laravels.php
'register_providers'       => [
    App\Providers\AuthServiceProvider::class,
    Tymon\JWTAuth\Providers\LaravelServiceProvider::class,
],
Event::listen('laravels.received_request', function (\Illuminate\Http\Request $req, $app) {
     Facade::clearResolvedInstance('auth');
 });

from laravel-s.

Eli-jah avatar Eli-jah commented on May 3, 2024

Problem solved partially, at least by now. Here is the solution:

Coding @ config/laravels.php as follows:

'register_providers' => [
        /* middleware service providers */
        Dingo\Api\Provider\DingoServiceProvider::class,
        Dingo\Api\Provider\HttpServiceProvider::class,
        /* auth service providers */
        Illuminate\Auth\AuthServiceProvider::class,
        App\Providers\AuthServiceProvider::class,
        Tymon\JWTAuth\Providers\LaravelServiceProvider::class,
],

Give it a try, and wish it would work for you, too.

from laravel-s.

Yoruchiaki avatar Yoruchiaki commented on May 3, 2024

使用以下方法并未生效

# config/laravels.php
'register_providers'       => [
    App\Providers\AuthServiceProvider::class,
    Tymon\JWTAuth\Providers\LaravelServiceProvider::class,
],
Event::listen('laravels.received_request', function (\Illuminate\Http\Request $req, $app) {
     Facade::clearResolvedInstance('auth');
 });

from laravel-s.

hhxsv5 avatar hhxsv5 commented on May 3, 2024

@Yoruchiaki 不要乱试了,先跟踪下代码找到User数据缓存在哪里了,再看情况清理对应对象或属性即可。因为各个版本Laravel 存储User数据位置不一样,不能给出一个很完美的解决方案,需要根据自己情况处理。

反正核心**就是要清理这些被缓存的数据。

class AuthManger
{
      private $user;
      public function getUser()
      {
          if (is_null($this->user)) {
             $this->user = $this->findUser($sessionId);
          }
          return $this->user;
      }
}

$this->app->singleton('auth', function ($app) {
    return new AuthManager($app);
});

将AuthManger注册为单例后,每个Swoole Worker进程内都会有一个这样的单例。同一进程内,上次请求存储的用户数据,其他请求就会读取到这个用户数据,所以需要每次请求开始 或 结束 清理对应的单例或成员数据。

from laravel-s.

dafa168 avatar dafa168 commented on May 3, 2024

这个全局中间件设置了但是没啥效果。@flymorn

from laravel-s.

hhxsv5 avatar hhxsv5 commented on May 3, 2024

@ALL After a week of debugging, I have passed the test locally for the Laravel/Lumen 5.1-5.8 user authorization. Please try the Master branch code(composer require hhxsv5/laravel-s:dev-master -vvv), if there is no problem, I will release v3.4.0, thanks for your support.

from laravel-s.

hhxsv5 avatar hhxsv5 commented on May 3, 2024

And you need to republish configuration php artisan laravels publish.

from laravel-s.

hhxsv5 avatar hhxsv5 commented on May 3, 2024

v3.4.0

from laravel-s.

pensacola1989 avatar pensacola1989 commented on May 3, 2024

Hi,已经更新到了3.4.1,依然有问题。。。

hhxsv5/laravel-s                    v3.4.1             🚀LaravelS is a glue that is used to quickly integrate Swoole into Laravel or Lumen and then give them be...

from laravel-s.

hhxsv5 avatar hhxsv5 commented on May 3, 2024

最终解决方案:打开清理器,不要重新注册AuthServiceProvider

from laravel-s.

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.