swoole / swoole-src

🚀 Coroutine-based concurrency library for PHP
https://www.swoole.com
Apache License 2.0
18.45k stars 3.16k forks source link

Sessions support? #1716

Closed sshymko closed 6 years ago

sshymko commented 6 years ago

PHP process is designed to handle a single request with a single session context. In case of Swoole, single process will be handling multiple requests, each requiring its own session context.

Is Swoole completely incompatible with PHP sessions? Functions session_* cannot be used, correct?

How to implement sessions with Swoole?

twose commented 6 years ago

Yes, you must implement it by yourself. PHP session depends on $_COOKIE and use the files to save the session context. You can create a session table in the database, use $response->setcookie to give the client a random token, save the token in the database, through $request->cookies attribute to get client session-token and find it in the database. You can see the repo https://github.com/swoft-cloud/swoft-session, Or just use swoft framework.

huangzhhui commented 6 years ago

You could use https://github.com/swoft-cloud/swoft directly, or see https://github.com/swoft-cloud/swoft-session for reference

sshymko commented 6 years ago

@twose and @huangzhhui, Thanks for the quick response! Closing.