Comments (17)
@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.
解决方法:
第一步: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.
使用jwt,二个用户同时请求这个返回结果都一样了,二个人的信息是不一样的
from laravel-s.
@igo9go 在配置中重新注册下ServiceProvider即可,here
from laravel-s.
我使用jwt也是有同样问题,两个用户同时请求两个人的信息就会变成一样的,register_providers已经添加了JWT的JWTAuthServiceProvider。
系统环境:Ubuntu16.04
JWT:"tymon/jwt-auth": "^0.5.12"
laravel-s:"hhxsv5/laravel-s": "~3.0"
from laravel-s.
上线前手贱升级了laravels的版本,发现最新的V3.1.0设置了register_provider还是不行,auth实例还是被cache起来了,没有被清除掉。配置不变,换回V2.0.7又一切正常。 @hhxsv5
from laravel-s.
已解决该问题,说下我的方法:
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.
根本原因还是单例问题。
方案:
- 重新注册Provider:
# config/laravels.php
'register_providers' => [
App\Providers\AuthServiceProvider::class,
Tymon\JWTAuth\Providers\LaravelServiceProvider::class,
],
- 系统事件laravels.received_request中清理Facade
auth
Event::listen('laravels.received_request', function (\Illuminate\Http\Request $req, $app) {
Facade::clearResolvedInstance('auth');
});
from laravel-s.
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.
使用以下方法并未生效
# 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.
@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.
这个全局中间件设置了但是没啥效果。@flymorn
from laravel-s.
@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.
And you need to republish configuration php artisan laravels publish
.
from laravel-s.
from laravel-s.
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.
最终解决方案:打开清理器,不要重新注册AuthServiceProvider
。
from laravel-s.
Related Issues (20)
- 请问如果使用的Sanctum 轻量级 API 认证,第二次通过request->user()结果为null 这么配置解决? HOT 2
- 请问 laravel/sanctum 怎么正确使用在laravel-s 项目上 HOT 7
- 请问如何启动服务时仅开启ws服务 HOT 2
- 系统偶发报connect() to unix:/dev/shm/live-server.sock failed HOT 6
- 开启了自定义进程process, 使用laravels stop命令不能关闭服务器 HOT 2
- nginx代理后怎么获取客户端真实IP呢? HOT 2
- Telescope 请求跟踪问题 HOT 1
- does not exist, or permission denied HOT 1
- `App\Console\Commands`下的创建的自定义命令中调用`app('swoole')`显示`Target class [swoole] does not exist`. HOT 2
- [QUESTION] quit property on custom process during reload
- 我使用这个只使用ws服务,其他业务使用了fpm模式,发现一个问题 HOT 1
- tcp socket onConnect 里面能使用数据库模型,onReceive 不能使用,啥原因 HOT 1
- Target class [swoole] does not exist error in console command with laravels server start and up HOT 2
- dcat-admin使用问题 HOT 1
- LaravelS 3.7.37 Optimized the call of schedule:run command Issue HOT 1
- 配置项 `register_providers` 不生效 HOT 2
- 启动的工作目录问题 HOT 1
- The operation of websockets and dispatch_mode HOT 3
- laravels master 内存没释放 HOT 2
- Response time increases possible memory leaks HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from laravel-s.