New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

failed to start session while using swoole #27

Closed
azjezz opened this Issue Oct 4, 2018 · 10 comments

Comments

Projects
None yet
3 participants
@azjezz

azjezz commented Oct 4, 2018

the library works as it supposed to using Apache, nginx or PHP built-in web-server, but that's not the case with swoole ( zendframework/zend-expressive-swoole ), i don't know how am i supposed to start the session or if this library is not compatible with swoole maybe?

composer requirements :

        "php": "^7.2",
        "ext-fileinfo": "*",
        "ext-hash": "*",
        "ext-json": "*",
        "ext-mbstring": "*",
        "ext-pdo": "*",
        "ext-swoole": "*",
        "dasprid/container-interop-doctrine": "dev-master",
        "league/commonmark": "^0.17.5",
        "league/commonmark-extras": "^0.1.4",
        "monolog/monolog": "^1.23",
        "paragonie/csp-builder": "^2.3",
        "psr/cache": "^1.0",
        "psr/container": "^1.0",
        "psr/http-factory": "^1.0",
        "psr/http-message": "^1.0",
        "psr/http-server-handler": "^1.0",
        "psr/http-server-middleware": "^1.0",
        "psr/log": "^1.0",
        "psr/simple-cache": "^1.0",
        "symfony/cache": "^4.1",
        "symfony/dotenv": "^4.1",
        "symfony/polyfill": "^1.9",
        "symfony/validator": "^4.1",
        "validus/translation": "^1.0.1",
        "zendframework/zend-component-installer": "^2.1.1",
        "zendframework/zend-config-aggregator": "^1.0",
        "zendframework/zend-diactoros": "^1.7.1",
        "zendframework/zend-expressive": "^3.0.1",
        "zendframework/zend-expressive-csrf": "^1.0",
        "zendframework/zend-expressive-flash": "^1.0",
        "zendframework/zend-expressive-helpers": "^5.0",
        "zendframework/zend-expressive-session": "^1.1",
        "zendframework/zend-expressive-session-ext": "^1.2",
        "zendframework/zend-expressive-swoole": "^1.0",
        "zendframework/zend-expressive-tooling": "^1.0",
        "zendframework/zend-expressive-twigrenderer": "^2.0",
        "zendframework/zend-expressive-zendrouter": "^3.0",
        "zendframework/zend-mail": "^2.10",
        "zendframework/zend-servicemanager": "^3.3",
        "zendframework/zend-stdlib": "^3.1"

This is the logged exception :

[2018-10-05 00:28:48] Polar.CRITICAL: Unexpected Exception : session_start(): Headers already sent. You cannot change the session module's ini settings at this time {"message":"session_start(): Headers already sent. You cannot change the session module's ini settings at this time","code":0,"file":"/home/azjezz/Documents/projects/polar/vendor/zendframework/zend-expressive-session-ext/src/PhpSessionPersistence.php","line":154,"trace":[{"function":"Zend\\Stratigility\\Middleware\\{closure}","class":"Zend\\Stratigility\\Middleware\\ErrorHandler","type":"->","args":[2,"session_start(): Headers already sent. You cannot change the session module's ini settings at this time","/home/azjezz/Documents/projects/polar/vendor/zendframework/zend-expressive-session-ext/src/PhpSessionPersistence.php",154,{"id":"24c029f3fa5fed0a53582aaaf1eb6535","options":[]}]},{"file":"/home/azjezz/Documents/projects/polar/vendor/zendframework/zend-expressive-session-ext/src/PhpSessionPersistence.php","line":154,"function":"session_start","args":[{"use_cookies":false,"use_only_cookies":true,"cache_limiter":""}]},{"file":"/home/azjezz/Documents/projects/polar/vendor/zendframework/zend-expressive-session-ext/src/PhpSessionPersistence.php","line":93,"function":"startSession","class":"Zend\\Expressive\\Session\\Ext\\PhpSessionPersistence","type":"->","args":["24c029f3fa5fed0a53582aaaf1eb6535"]},{"file":"/home/azjezz/Documents/projects/polar/vendor/zendframework/zend-expressive-session/src/LazySession.php","line":122,"function":"initializeSessionFromRequest","class":"Zend\\Expressive\\Session\\Ext\\PhpSessionPersistence","type":"->","args":["[object] (Zend\\Diactoros\\ServerRequest: {})"]},{"file":"/home/azjezz/Documents/projects/polar/vendor/zendframework/zend-expressive-session/src/LazySession.php","line":70,"function":"getProxiedSession","class":"Zend\\Expressive\\Session\\LazySession","type":"->","args":[]},{"file":"/home/azjezz/Documents/projects/polar/vendor/zendframework/zend-expressive-flash/src/FlashMessages.php","line":166,"function":"has","class":"Zend\\Expressive\\Session\\LazySession","type":"->","args":["Zend\\Expressive\\Flash\\FlashMessagesInterface::FLASH_NEXT"]},{"file":"/home/azjezz/Documents/projects/polar/vendor/zendframework/zend-expressive-flash/src/FlashMessages.php","line":56,"function":"prepareMessages","class":"Zend\\Expressive\\Flash\\FlashMessages","type":"->","args":["[object] (Zend\\Expressive\\Session\\LazySession: {})","Zend\\Expressive\\Flash\\FlashMessagesInterface::FLASH_NEXT"]},{"file":"/home/azjezz/Documents/projects/polar/vendor/zendframework/zend-expressive-flash/src/FlashMessages.php","line":66,"function":"__construct","class":"Zend\\Expressive\\Flash\\FlashMessages","type":"->","args":["[object] (Zend\\Expressive\\Session\\LazySession: {})","Zend\\Expressive\\Flash\\FlashMessagesInterface::FLASH_NEXT"]},{"file":"/home/azjezz/Documents/projects/polar/vendor/zendframework/zend-expressive-flash/src/FlashMessageMiddleware.php","line":65,"function":"createFromSession","class":"Zend\\Expressive\\Flash\\FlashMessages","type":"::","args":["[object] (Zend\\Expressive\\Session\\LazySession: {})","Zend\\Expressive\\Flash\\FlashMessagesInterface::FLASH_NEXT"]},{"file":"/home/azjezz/Documents/projects/polar/vendor/zendframework/zend-expressive/src/Middleware/LazyLoadingMiddleware.php","line":46,"function":"process","class":"Zend\\Expressive\\Flash\\FlashMessageMiddleware","type":"->","args":["[object] (Zend\\Diactoros\\ServerRequest: {})","[object] (Zend\\Stratigility\\MiddlewarePipe: {})"]},{"file":"/home/azjezz/Documents/projects/polar/vendor/zendframework/zend-stratigility/src/MiddlewarePipe.php","line":78,"function":"process","class":"Zend\\Expressive\\Middleware\\LazyLoadingMiddleware","type":"->","args":["[object] (Zend\\Diactoros\\ServerRequest: {})","[object] (Zend\\Stratigility\\MiddlewarePipe: {})"]},{"file":"/home/azjezz/Documents/projects/polar/vendor/zendframework/zend-expressive-session/src/SessionMiddleware.php","line":34,"function":"handle","class":"Zend\\Stratigility\\MiddlewarePipe","type":"->","args":["[object] (Zend\\Diactoros\\ServerRequest: {})"]},{"file":"/home/azjezz/Documents/projects/polar/vendor/zendframework/zend-expressive/src/Middleware/LazyLoadingMiddleware.php","line":46,"function":"process","class":"Zend\\Expressive\\Session\\SessionMiddleware","type":"->","args":["[object] (Zend\\Diactoros\\ServerRequest: {})","[object] (Zend\\Stratigility\\MiddlewarePipe: {})"]},{"file":"/home/azjezz/Documents/projects/polar/vendor/zendframework/zend-stratigility/src/MiddlewarePipe.php","line":78,"function":"process","class":"Zend\\Expressive\\Middleware\\LazyLoadingMiddleware","type":"->","args":["[object] (Zend\\Diactoros\\ServerRequest: {})","[object] (Zend\\Stratigility\\MiddlewarePipe: {})"]},{"file":"/home/azjezz/Documents/projects/polar/vendor/zendframework/zend-expressive-helpers/src/ServerUrlMiddleware.php","line":37,"function":"handle","class":"Zend\\Stratigility\\MiddlewarePipe","type":"->","args":["[object] (Zend\\Diactoros\\ServerRequest: {})"]},{"file":"/home/azjezz/Documents/projects/polar/vendor/zendframework/zend-expressive/src/Middleware/LazyLoadingMiddleware.php","line":46,"function":"process","class":"Zend\\Expressive\\Helper\\ServerUrlMiddleware","type":"->","args":["[object] (Zend\\Diactoros\\ServerRequest: {})","[object] (Zend\\Stratigility\\MiddlewarePipe: {})"]},{"file":"/home/azjezz/Documents/projects/polar/vendor/zendframework/zend-stratigility/src/MiddlewarePipe.php","line":78,"function":"process","class":"Zend\\Expressive\\Middleware\\LazyLoadingMiddleware","type":"->","args":["[object] (Zend\\Diactoros\\ServerRequest: {})","[object] (Zend\\Stratigility\\MiddlewarePipe: {})"]},{"file":"/home/azjezz/Documents/projects/polar/src/Polar/Middleware/ErrorLoggingMiddleware.php","line":40,"function":"handle","class":"Zend\\Stratigility\\MiddlewarePipe","type":"->","args":["[object] (Zend\\Diactoros\\ServerRequest: {})"]},{"file":"/home/azjezz/Documents/projects/polar/vendor/zendframework/zend-expressive/src/Middleware/LazyLoadingMiddleware.php","line":46,"function":"process","class":"Polar\\Middleware\\ErrorLoggingMiddleware","type":"->","args":["[object] (Zend\\Diactoros\\ServerRequest: {})","[object] (Zend\\Stratigility\\MiddlewarePipe: {})"]},{"file":"/home/azjezz/Documents/projects/polar/vendor/zendframework/zend-stratigility/src/MiddlewarePipe.php","line":78,"function":"process","class":"Zend\\Expressive\\Middleware\\LazyLoadingMiddleware","type":"->","args":["[object] (Zend\\Diactoros\\ServerRequest: {})","[object] (Zend\\Stratigility\\MiddlewarePipe: {})"]},{"file":"/home/azjezz/Documents/projects/polar/vendor/zendframework/zend-stratigility/src/Middleware/ErrorHandler.php","line":143,"function":"handle","class":"Zend\\Stratigility\\MiddlewarePipe","type":"->","args":["[object] (Zend\\Diactoros\\ServerRequest: {})"]},{"file":"/home/azjezz/Documents/projects/polar/vendor/zendframework/zend-expressive/src/Middleware/LazyLoadingMiddleware.php","line":46,"function":"process","class":"Zend\\Stratigility\\Middleware\\ErrorHandler","type":"->","args":["[object] (Zend\\Diactoros\\ServerRequest: {})","[object] (Zend\\Stratigility\\MiddlewarePipe: {})"]},{"file":"/home/azjezz/Documents/projects/polar/vendor/zendframework/zend-stratigility/src/MiddlewarePipe.php","line":78,"function":"process","class":"Zend\\Expressive\\Middleware\\LazyLoadingMiddleware","type":"->","args":["[object] (Zend\\Diactoros\\ServerRequest: {})","[object] (Zend\\Stratigility\\MiddlewarePipe: {})"]},{"file":"/home/azjezz/Documents/projects/polar/vendor/zendframework/zend-expressive-swoole/src/SwooleRequestHandlerRunner.php","line":318,"function":"handle","class":"Zend\\Stratigility\\MiddlewarePipe","type":"->","args":["[object] (Zend\\Diactoros\\ServerRequest: {})"]}]} []

Expected results

  • session starts normally without any errors.

Actual results

  • session doesn't start and an exception being thrown by the error handler set in the Zend\Stratigility\Middleware\ErrorHandler middleware
@azjezz

This comment has been minimized.

azjezz commented Oct 4, 2018

@weierophinney

This comment has been minimized.

Member

weierophinney commented Oct 5, 2018

@azjezz

This comment has been minimized.

azjezz commented Oct 6, 2018

thanks for clarifying @weierophinney , i have just finished my validus/cache package, does your session persistence accept any psr6/psr16 implementation or does it include one that it uses ?

@weierophinney

This comment has been minimized.

Member

weierophinney commented Oct 6, 2018

@azjezz

This comment has been minimized.

azjezz commented Oct 7, 2018

@weierophinney i had nothing to do today, and i needed sessions to continue working on my application so i made something similar to what you are working on, its missing some features ( cookies options, session regeneration .. etc ), but i'll be using it until the PSR16 session persistence is ready.

https://gist.github.com/azjezz/8a32d87df39422a12e3078a35a8c988a

one thing i noticed while doing this ( took me almost 2 hours to track it down ) is that the request is missing 'Cookie' header, so i had to obtain the session cookie from the cookies parameters : $request->getCookieParams();, is that normal ?

@weierophinney

This comment has been minimized.

Member

weierophinney commented Oct 7, 2018

@azjezz

This comment has been minimized.

azjezz commented Oct 7, 2018

@weierophinney i guess that's 1 reason why this package is not compatible with swoole then.

@froschdesign

This comment has been minimized.

Member

froschdesign commented Oct 8, 2018

@azjezz
Can you explain why you think this package is not compatible with Swoole?

@weierophinney

This comment has been minimized.

Member

weierophinney commented Oct 8, 2018

@azjezz and @froschdesign — The reason this package isn't compatible with swoole is because Swoole runs in the CLI, and the CLI SAPI doesn't work with ext-session. It has nothing to do with where cookie information is found in the request instance.

Part of the reason we introduced zend-expressive-session in the first place is because we already knew that ext-session would not be a viable way to handle sessions when you run Expressive in non-traditional environments. At the time, it was due to experiments with ReactPHP, but that experience could be extrapolated to Icicle, Swoole, etc. This was the reason we ensured that zend-expressive-session could work directly with a PSR-7 request only. Now we just need to introduce adapters that do not use ext-session to demonstrate this feature. As I've noted previously in the thread, I've created one for myself that uses PSR-6, and I'll try and get it posted in the next couple days.

@azjezz

This comment has been minimized.

azjezz commented Oct 14, 2018

this issue should be closed as this package is not compatible with swoole.

a new session persistence has been release which support swoole that makes use of PSR-6 cache.
zendframework/zend-expressive-session-cache
i have made a package that provides container factories for symfony/cache which is compatible with PSR-6 and zend component installer that you can use.
validus/cache

@azjezz azjezz closed this Oct 14, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment