joanhey / AdapterMan

Run almost any PHP app faster and asynchronously with Workerman, without touch 1 line of code in your fw or app. Also use it as Serverless.
https://twitter.com/adaptermanphp
MIT License
759 stars 50 forks source link

laravel can be use session login? #1

Open mouyong opened 2 years ago

joanhey commented 2 years ago

Not in Symfony demo.

We are fixing it.

joanhey commented 2 years ago

I'm testing with Laravel Orchid admin, and it's working. But still testing and fixing the session.

joanhey commented 2 years ago

Fixed in Symfony and Laravel.

mouyong commented 1 year ago

good job. maybe we can close project laravel-octane-workerman

mouyong commented 1 year ago

10

joanhey commented 1 year ago

Why create a lib for only 1 framework, when we can create one (Adapterman) that we can use with almost any framework or app.

Only one lib to maintain, for all the frameworks.

joanhey commented 1 year ago

After more checking, work but not correctly. It's nothing about Adapterman-Workerman.

I'm now trying to fix it. From the Laravel side. Laravel session, don't use Symfony session that use the normal $_SESSION from PHP or Workerman.

So we'll need to add 2 lines of code for clean the session, in any new request.

joanhey commented 1 year ago

From @493226876

OK, thank you for telling me. I always thought that it was a problem where I set up the session. The session has always been repeated. It was originally a mechanism problem. If you have any trouble, please let me know. Thank you

How do you set up the session and auth in Laravel, will be a problem with any worker mode: adapterman, laravel-swoole, Octane, ....

You can't do that, in any worker mode:

namespace App\Http\Controllers;
class TestController extends Controller
{
    protected $userId;
    public function __construct()
    {
        // Wrong usage: Since the controller is only constructed once and then resident in memory, $userId will only be assigned once, and subsequent requests will be misread before requesting $userId
        $this->userId = session('userId');
    }
    public function testAction()
    {
        // read $this->userId;
    }
}

Corect:

namespace App\Http\Controllers;

class TestController extends Controller
{
    protected function getUserId()
    {
        return session('userId');
    }
    public function testAction()
    {
        // call $this->getUserId() to read $userId
    }
}

This week, I'll try with Shared Nothing mode, that for sure will work. But the performance will be in the middle of php-fpm and worker mode.

The problem is from the Laravel side. And we are talking with Laravel devs to clean the session and auth in each request, but from the Laravel side. We will release the solution.