You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This PR was squashed before being merged into the 5.4 branch.
Discussion
----------
[HttpKernel] Add session cookie handling in cli context
| Q | A
| ------------- | ---
| Branch? | 5.4
| Bug fix? | no
| New feature? | no <!-- please update src/**/CHANGELOG.md files -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tickets | Fix#42890
| License | MIT
| Doc PR | symfony/symfony-docs#... <!-- required for new features -->
Currently the session cookie is never set on the `request` object. In a normal webserver setup this is not needed as a session is in php-fpm or apache fastcgi written by php itself when the response is outputted in: https://github.com/symfony/symfony/blob/744b901750c1cc09e85bcb2ebdf0505449a1158f/src/Symfony/Component/HttpFoundation/Response.php#L393
When use a runner like `Roadrunner` the `session` cookie is never set on the `Request` object, as this kind of appserver never really outputs something and is running in the `cli` context.
Actually there is no way from outside to know if `$session->save()` was called or not because when the code in `Roadrunner` executes the session is actually written and so closed here: https://github.com/symfony/symfony/blob/744b901750c1cc09e85bcb2ebdf0505449a1158f/src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php#L279.
The best way so to fix this issue is that in CLI context symfony writes the session cookie on the `Response` object when the session is really saved.
This fixes issues which we have in the current roadrunner implementation of php runtime:
- [x] https://github.com/php-runtime/roadrunner-symfony-nyholm/blob/58665237ef2bff08a1ebf269e64abbf8cd09fbd7/src/Runner.php#L89
- [x] https://github.com/php-runtime/roadrunner-symfony-nyholm/blob/58665237ef2bff08a1ebf269e64abbf8cd09fbd7/src/Runner.php#L81
Beside Roadrunner there is also Swoole implementation which would require the same here: php-runtime/runtime#60
With this changes the Runners can be simplified a lot: https://github.com/php-runtime/runtime/pull/62/files#
## TODO
Reset session variables after successfully response. The following code currently lives also in the runtime implementation but is requires also by all runners and so we should find a place where we put it:
```
if (PHP_SESSION_ACTIVE === session_status()) {
session_abort();
}
// reset all session variables to initialize state
$_SESSION = [];
session_id(''); // in this case session_start() will generate us a new session_id()
```
EDIT: Added this now to the `AbstractSessionListener` service via `ResetInterface`.
Commits
-------
b3e4f66 [HttpKernel] Add session cookie handling in cli context
0 commit comments