roadrunner-server / roadrunner

🤯 High-performance PHP application server, process manager written in Go and powered with plugins
https://docs.roadrunner.dev
MIT License
7.86k stars 408 forks source link

Laravel - sessions don't work (cookies problem) #91

Closed osbre closed 5 years ago

osbre commented 5 years ago

Steps to reproduce

How to fix it? thanks

wolfy-j commented 5 years ago

Can it be related to https://github.com/spiral/roadrunner/issues/18 ?

osbre commented 5 years ago

@wolfy-j maybe yes

Alex-Bond commented 5 years ago

@wolfy-j @Ostap34JS I think it caused by #93

osbre commented 5 years ago

@Alex-Bond wow, Thank you for fix!

Then i`m wait to pull request will be merged

wolfy-j commented 5 years ago

Merged and released.

osbre commented 5 years ago

Coool, ok - i`m go to try new changes

osbre commented 5 years ago

i'm go to my roadrunner cloned directory, run git pull , and sudo make and run my laravel project - sessions also not work.

wolfy-j commented 5 years ago

The fix is actually in composer dependency not rr binary.

osbre commented 5 years ago

i'm updated my composer dependencies (composer update) , and run project again (rr serve -v -d)

sorry, too don't work - it return 419

Alex-Bond commented 5 years ago

@Ostap34JS can you check if CSRF code sending to the server when you submitting the form?

osbre commented 5 years ago

ok, checking... thank you

if you want see config: https://github.com/Ostap34JS/roadrunner-laravel-test

osbre commented 5 years ago

oh yes, csrf token exists, but it always change if page refreshed

osbre commented 5 years ago

the problem is that the csrf token is not saving and always updated

Alex-Bond commented 5 years ago

@Ostap34JS i love Laravel. Not it doesn't see cookies... in some cases.

osbre commented 5 years ago

it's bad (

Alex-Bond commented 5 years ago

@Ostap34JS actually now its working, but i didnt change anything.

osbre commented 5 years ago

You mean in your computer it works?

Alex-Bond commented 5 years ago

@Ostap34JS yeap. Sorry for russian :)

Проверил в инкогнито и обычном режиме - вс еок. Дает зарегаться и залогинится. Но столкнулся с странным поведением когда я делаю логаут, но он не логаутит. Это я уже хз что за фигня. Возможно где-то не донастроил сесии в ларе.

wolfy-j commented 5 years ago

А при логауте как он удаляет куки?

osbre commented 5 years ago

@Alex-Bond :)

у меня кстати тоже такое было, но потом вообще перестало логинить

Alex-Bond commented 5 years ago

@wolfy-j @Ostap34JS при логауте согласно коду он просто обнуляет сессию (атрибуты в []). Но вместе с этим он создает новую сессию и отправляет новую куку с сессией. А дальше начинается веселая часть - при ребуте он то считает что я залогинен, то нет. Такое чувство что прописывает что то в $_SESSION и $_COOKIE, но при дебаге все чисто. Не пойму откуда эта скотина берет не те данные.

Alex-Bond commented 5 years ago

Меня еще сильно ссмущает то что он шлет set-cookie 2 раза подряд.

wolfy-j commented 5 years ago

Если он прописывает что-то в $_SESSION и $_COOKIE то однозначно утекают данные в следующий запрос... Трудно сказать, мы не пользуемся Ларавел (

wolfy-j commented 5 years ago

А ядро Ларавела перезагружается между запросами?

Alex-Bond commented 5 years ago

@wolfy-j дак и так делается терминейт между запросами как в симфе. Он вроде не пишет, но есть чутье что что-то в глобалку он всетаки умудряется писать.

osbre commented 5 years ago

@wolfy-j да

wolfy-j commented 5 years ago

А если maxJobs = 1 то работает стабильно?

Alex-Bond commented 5 years ago

@wolfy-j сделал numWorkers: 1 и все стало стабильно. 100% глобалка гдето. Осталось понять где!

Alex-Bond commented 5 years ago

Нащупал что то интерестное. \Illuminate\Auth\SessionGuard не обнуляется при выставлении нового запроса. Теперь надо придумать как его поправить.

Alex-Bond commented 5 years ago

@wolfy-j @Ostap34JS So, a small update in English because i feel like i figure out a problem. Looks like Laravel doesn't reset few components with terminate() call and we have to reset it manually. In order to do that, i have to create a wrapper around an application like https://github.com/php-pm/php-pm-httpkernel have. Its already 4AM (4:00) at my place, so i will look into this before the end of the week.

wolfy-j commented 5 years ago

Thank you for digging in, this explains a lot.

AlexPravdin commented 5 years ago

Sorry for offtopic, but similar issue. With Symfony 4.2 I had to send session cookie headers to the $response object and regenerate/update session variables manually within the RR bootstrap. Is it correct? Current RR bootstrap example in the docs don't have workarounds for session support.

barbushin commented 5 years ago

I think, for complete Laravel/Lumen integration with best performance, it will be great to implement same service providers and DI instances resets logic as here https://github.com/swooletw/laravel-swoole/blob/master/config/swoole_http.php#L92-L120

wolfy-j commented 5 years ago

Please refer to https://github.com/spiral/roadrunner/issues/96

wolfy-j commented 5 years ago

@barbushin this story has been addressed by #96. Can you please put your ideas/links regarding performance optimizations into separate story so we can avoid loosing it?

Thank you :)