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

franvillada's avatar

File session driver not working properly on production

When using session on my local environment all worked ok, but when I publish the site in a shared hosting I started noticing some strange behaviuours in the app. After a while I realized it has to do with the session an especifically I noticed that when I was working on my local environment the storage/framework/sessions folder only had 1 file that keep updating on any change but then on production I start monitoring the same folder and I realized that on any change instead of updating the file (or creating a new one and deleting the other) it was creating a new file but also keeping the old files making the app start acting in a wrong way.

Is this normal or should it be only 1 file per session as it was in the local environment?

If someone could give me some thoughts about this I will really appreciate, I need to lunch the app ASAP and Im not able to figure out how to make it work properly.

0 likes
6 replies
jlrdw's avatar

You're going to have several sessions at times. Are people already using your site and logging in, that's where session data comes from. Logins and anything stored in session per user.

franvillada's avatar

Yes I understand that, but im the only one using the site and the problem is that for the same session in this case my session i have a lot of files that they keep creating every time I store something in the session. When I use the site in my local environment it works ok, every time I store something it keeps the session file and update it but in the shared host it creates a new file instead

jlrdw's avatar

I've actually not noticed one way or the other in hosting versus local but if session is working you're probably okay, I have no idea if it has to do with cache or what. I know in regular PHP sessions you will see quite a few at times and periodically they Auto Purge out.

I'm going to reread the Chapter on sessions to see if it mentions anything about that. But I imagine you have opened the sessions to ensure it's the correct data, right

And I always just use regular file session.

franvillada's avatar

Yes the sessions files have the correct data but when I make a change in a property of the sessions it creates a new session_id thats the problem.

I dont understand why it is doing this because in my local environment the session_id persist after any change on the session.

franvillada's avatar

After days of trying to figure it out, I just figure out the solution.

Instead of using the Global Helpers of Laravel for storing the data I did it throw the request and apparently that work it out.

So basically instead of doing this:

session('clienteElegido' => $client);

I change it for this:

$request->session()->put('clienteElegido',$client);

I still dont understand what's the difference and why it was working fine in my local environment and not in the share host but its working now like that so all good.

Thank you for all the quick replies.

Please or to participate in this conversation.