Phalcon 4.x Sessions Via MySQL?

I've looked at the incubator repo on GitHub for the MySQL session adapter and it seems that it's not up to date with Phalcon 4.x in terms of getting sessions logged within MySQL rather than relying on the Stream adapter to store sessions via files.

I have an app that is starting to get massive traffic and while I'm able to spin up more servers in a load balancer, it becomes an issue keeping the session files synced between multiple servers. If a user on server A gets logged in and then is kicked to server B because of load balancing, they aren't logged in anymore and have to re-create their session.

I'm trying to figure out either a.) what needs to be done to get that incubator script up to date, b.) need an already up to date adapter that someone knows of or c.) how exactly to create my own adapter to properly work with the session adapter interface.

I've been google searching this issue for weeks now and I find it weird nobody has found a solution yet. Maybe I'm missing a thread that got buried?

Any help would be greatly appreciated.

P.S. - On a side note, is there any way with the Stream Adapter for sessions to be set to a time limit? I'm having trouble finding how to do that in the docs.

edited Aug '20

You can use memcached locally sharing it to your servers behind the load balancer.
https://docs.phalcon.io/4.0/fr-fr/session#libmemcached

You can use memcached locally sharing it to your servers behind the load balancer.
https://docs.phalcon.io/4.0/fr-fr/session#libmemcached

Thanks for the suggestion! Unfortunately, because we have developers working on local copies of the website (across Mac, Windows and Linux) and pushing their work through GitHub for review and deployment, adding on to their plate the need to setup and run memcache as part of their local environment would be extremely cumbersome.

The ideal situation would be to get sessions stored via MySQL, as their environments already have that in place and because we plan to leverage session data within the database for analytics and support for users within the app.

I've been trying to wrap my head around the docs regarding making a custom adapter for sessions in Phalcon 4.x, and it seems that the main change was the naming convention. Am I correct in assuming that if I update the class names and paths in the incubator script to use the correct namespaces in Phalcon 4.x that it should be smooth sailing from there?

Yes but you should use it only in production and in developpement stay with the stream adapter, your developers doesn't need to share their sessions.
I can't help you about custom adapter, I nerver used it, but maybe namespace update is enough.



6.5k

if there is no sensitive data why not use jwt