Share Session using Redis

Asked

Viewed 60 times

2

I have the following setup on AWS:

  1. Application with php5.6
  2. Application with Laravel 6
  3. Loadbalancer
  4. Elasticcache Redis

Loadbalancer separates certain route for PHP application and other routes for Laravel I installed in PHP the extension php5-redis and it worked perfect the connection I installed in Laravel the Predis package and made the configuration too

The sessions are saving like this in PHP:

"PHPREDIS_SESSION:3mm1j1s38io0qqsjo9h1i5k0e7" "1440" "id_log_acesso|s:8:\"22684247\";last_session|s:26:\"3mm1j1s38io0qqsjo9h1i5k0e7\";"

And in Laravel saved so:

_sessao_aplicacao_cache:8IITIOGBIDNWfuF3FpY47c03FSJx2yGzyQzsh3ny" "7200" "s:223:\"a:3:{s:6:\"_token\";s:40:\"StJV71z6IVC7W1Zme2m0GcI4wuNRhEtnWfwkGT7s\";s:9:\"_previous\";a:1:{s:3:\"url\";s:65:\"http://172.31.23.41/check-status-6d1127a34c48cd9722d16b7e20aaee70\";}s:6:\"_flash\";a:2:{s:3:\"old\";a:0:{}s:3:\"new\";a:0:{}}}\";"

The 2 instances share the same domain, who manages everything is the Loadbalancer

My question is: How do I share the same session for the 2 applications?

Grateful!

  • When there is the intention to share sessions between applications one must reset in both applications the session storage functions with session_set_save_handler() so that they operate on the same resources.

  • I did not understand the negative. The question is good and the situation in the labor market.

  • No negative came for me here, but I’ll take a look at session_set_save_handler() Try to match it to Laravel’s.. Grateful for the @Augustovasques tip

  • There was a negative yes, because I had given a positive in the question.

  • Ah pity :/ It did not count for me here, could have at least justified the negative

  • @Augustovasques do you have any practical example of this? :(

  • If I find something I leave the link later.

Show 2 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.