Skip to content
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

Setup redis session driver #2

Merged
merged 6 commits into from
Aug 23, 2022
Merged

Setup redis session driver #2

merged 6 commits into from
Aug 23, 2022

Conversation

azophy
Copy link
Owner

@azophy azophy commented Aug 23, 2022

  • setup redis container in docker-compose.yml
  • configure redis as session driver in both Laravel & Codeigniter

Problem in Codeigniter

  • CI version used by SIKD (3.1.8) has some bug regarding deprecated method in Predis. It should be upgraded to latest version.

Possible problem regarding Laravel-Codeigniter shared session mechanism:

  • both have different key format
  • both have different serialization strategy (laravel use JSON, while CI use some other method. maybe using PHP's serialize() or session_decode() method)?

Screen Shot 2022-08-23 at 12 20 20

possible solution: use a custom third party session driver to achieve uniform redis session storage mechanism

chosen solution

change both session serialization settings to use PHP's serialize() method

Screen Shot 2022-08-23 at 16 34 39

@azophy
Copy link
Owner Author

azophy commented Aug 23, 2022

@azophy
Copy link
Owner Author

azophy commented Aug 23, 2022

driver itu nanti di wrap oleh https://github.com/bcit-ci/CodeIgniter/blob/3.1-stable/system/libraries/Session/OldSessionWrapper.php , yang akhirnya nanti dijadikan driver utk session handler bawaan PHP

@azophy
Copy link
Owner Author

azophy commented Aug 23, 2022

@azophy
Copy link
Owner Author

azophy commented Aug 23, 2022

clue

kayaknya memang format di redis CI itu pakai serialisasi dari session_encode(). referensi

@azophy
Copy link
Owner Author

azophy commented Aug 23, 2022

Pencerahan: Laravel tidak memakai sistem session native dari PHP sama sekali :

https://github.com/laravel/framework/blob/9.x/src/Illuminate/Session/Middleware/StartSession.php#L112

berarti untuk serialisasinya perlu di utak atik lagi. kayaknya lebih gampang kalau codeigniter yang dibuat biar ngikut sistemnya Laravel

@azophy
Copy link
Owner Author

azophy commented Aug 23, 2022

baca2 lagi, pilihan format serializer session PHP cuman ada 3 opsi:

  • php_serialize : PHP serialize format
  • php/php_binary : PHP internal formats
  • wddx : WDDX are supported

kayaknya harus dirombak session handler nya CI biar pakai custom session class

@azophy
Copy link
Owner Author

azophy commented Aug 23, 2022

open source library that mimics PHP's session_encode() serialization method: https://github.com/wikimedia/php-session-serializer

@azophy
Copy link
Owner Author

azophy commented Aug 23, 2022

code snippet for emulating session_encode/decode serialization: https://stackoverflow.com/q/15538787

@azophy
Copy link
Owner Author

azophy commented Aug 23, 2022

interesting info:

  • ternyata serialisasi json di session laravel itu relatif baru. PR terkait: [9.x] JSON Session Option laravel/framework#40595
  • ternyata ada undocumented config session.serialization untuk ganti metode serialisasi dari json jadi php. kalau bisa begitu, berarti setting session.serialize_handler di codeigniter juga bisa diganti jadi php_serialize biar keduanya cocok

worth trying

change to use PHP's native serialization method
@azophy azophy marked this pull request as ready for review August 23, 2022 09:33
@azophy azophy merged commit 497ddd4 into main Aug 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant