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

RoelVB's avatar

[L5.3] Session randomly expires

Hi All,

I'm using Laravel 5.3.2 (but was also having this issue with 5.2.x). After some random time my session expires, sometimes it is two hours, sometimes just a minute. The session file disappears from /storage/framework/sessions.

In my session config I've set the lifetime to 120, I've had it at 900, but this didn't make any difference. Also the gc_maxlifetime in php.ini is set tot 86400.

0 likes
10 replies
RoelVB's avatar

Maybe any ideas how to debug this? This is a huge problem!

amitshrestha221's avatar

I also got this problem.. also in 5.1 .. The session expires and you redirect back to login page..

In three projects, I faced this problem.. It's actually not your fault.. when you upload to the server, this problem is solved automatically.. I dont know how but it disappears after uploading to server.

I hope it helps..

RoelVB's avatar

So that made me think, wat could be the difference between the development and live environment. Only think I could think of is the debug mode, so I set debugging to 'false'. Unfortunately the session expired in 10 minutes.

RoelVB's avatar

I think it might have something todo with (almost) simultaneous (AJAX) requests. This could also explain why the problem doesn't exist on a live server, because in most cases the connection to the live server are not as fast as the connection to a local development environment.

RoelVB's avatar

This is what the browsers development tools show me: Session timeout The two 'projects' request are (almost) simultaneous.

amitshrestha221's avatar

I guess thats the issue.. because two of my projects facing that problem was solved when uploaded to server..

RoelVB's avatar

Today I've only worked on pages without any AJAX. No problems there, my session is more than 7 hours old now. So it looks like this has something to do with AJAX requests.

Does anyone know if sessions are handled different for AJAX requests?

RoelVB's avatar

It is getting even stranger, now there is one random request with an expired session, but after that (without singing in) the session works again: One unauthorized

RoelVB's avatar

Switched the sessions te Redis (instead of file) today. Sessions has been working fine for 6 hours now. So Redis it is!

daleramirez's avatar

I encountered this problem and it took me time to figure it out. I am running Mamp on Windows. The problem is that i used many session other than the login session. It seems that Windows cannot handle multiple session update when there is to many session to update it destroys the session data.

My solution is to reduce number of session input or just use another session driver,

Please or to participate in this conversation.