Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

lyonio's avatar

Save some data in session to avoid db requests?

It is recommended to save some data in session to avoid on every call db requests? Sometime it can has also sensitive data..

recommended?

0 likes
2 replies
mdeorue's avatar

Store: session(['key' => $value]);

Get: session()->get('key');

Delete: session()->forget('key);

lostdreamer_nl's avatar

having sensitive data in the session does not need to be a problem if the session is kept on the server (file / db or anything)

If the queries are taking long, you should put it in the session. But be aware, the session could be in the DB itself (so still requiring a query) or file based on the server (file access is usually slower then a DB query)

Please or to participate in this conversation.