laravellaravel-sanctumlaravel-11laravel-octane

Timeout Issues using Laravel Sanctum & Octane together


I'm trying to migrate to Laravel Octane.

I use the cookie-based session authentication from Sanctum (React SPA) and use Laravel as an API.

I tried setting up Octane with Swoole, which caused lots of weird 408 timeout issues and also tried using FrankenPHP and Roadrunner, which also caused timeout issues.

I don't find any info about Sanctum and Octane working together. I'm mainly worried because I use cookie-based auth.

Edit:

I noticed having "DisconnectFromDatabases" not commented out solves the issues for FrankenPHP and Roadrunner (Didn't try Swoole again):

octane.php:

OperationTerminated::class => [
            FlushOnce::class,
            FlushTemporaryContainerInstances::class,
            DisconnectFromDatabases::class
            // CollectGarbage::class,
        ],

But it introduces a performance reduction. Im using a supabase database. Why does it solve the issue, and can I solve it differently without having the performance reduction?


Solution

  • Had to change the Supebase Database mode from session to transaction by using the env DB_PORT 6543 and had to add PDO Emulation in the database.php as I got PDO errors without that:

     'pgsql' => [
            'driver' => 'pgsql',
            'url' => env('DATABASE_URL'),
            'host' => env('DB_HOST', '127.0.0.1'),
            'port' => env('DB_PORT', '5432'),
            'database' => env('DB_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'charset' => 'utf8',
            'prefix' => '',
            'prefix_indexes' => true,
            'schema' => 'public',
            'sslmode' => 'prefer',
            'options' => [
                PDO::ATTR_EMULATE_PREPARES => true
            ],
        ],
    

    "DisconnectFromDatabases::class" can be commented out again (default setting). This cut the request duration in half!

    Im using Roadrunner, works good with heroku.

    Still curious if Sanctum and Octance could cause any issues in this setup like one user seeing data of another user? Is Sanctum designed to be stateless as needed for Octane?