2

I'm using Symfony session management system with PdoSessionHandler and I need to find specific session entry using user id saved in session data.

Because manually searching every session blob data could be costly my idea is to add another column into sessions table to specifically store user_id so I can tie session entry to the user.

My question is how to achieve this using existing Session module?

Another important info is that I'm using standalone Session module outside Symfony framework.

Here is simplified code that I use for initializing session module:

new Session(
  new NativeSessionStorage([], new PdoSessionHandler(new PDO())), 
  new NamespacedAttributeBag()
)
  • Looks like you would want to extend [`PdoSessionHandler`](https://symfony.com/doc/current/components/http_foundation/session_configuration.html#custom-save-handlers) or roll your own implementation extending `AbstractSessionHandler`. If you look at that code it would be trivial to alter `session` table, adding `user_id`, and reworking some of the functions on that class to account for it. – ficuscr Jul 03 '19 at 20:04
  • I'm well aware that would solve the problem, but I was trying to avoid that. For me this case seemed not so uncommon and yet I couldn't find any resources covering it. I hoped there is a better and faster way for achieving my goal. – Christopher Kalkhoff Jul 03 '19 at 21:34
  • Let me know if you find one.... But then I would be out of a job, wait. – ficuscr Jul 03 '19 at 21:35

0 Answers0