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

dinni's avatar
Level 1

Laravel session

Hi, My session file is becoming very big. How can i avoid this, My session lifetime is 20 hours is that the reason?

current files are 20 lakhs

0 likes
10 replies
Nakov's avatar

Which session file are you looking at? Is it the storage/framework/sessions directory?

What do you store in the session, and what is the lakhs metric? 20 hours is not long time.

Sinnbeck's avatar

@Nakov I think 20 lakhs is 2 million. That sounds implausible to me :)

Nakov's avatar

@Sinnbeck Thanks :D

and 2 million can be anything also.. 2 million bytes is 2 MB, not scary at all I guess

Nakov's avatar

@Sinnbeck might be, who knows :D

if it is 2 million files, that's a serious business :)

dinni's avatar
Level 1

@Nakov storage/framework/sessions yes,

it was 20 hours then i made as 365 days , in last 1 week files became 2000000+,

Nakov's avatar

@dinni That seems like a lot, do you have 2 million active users?

in your sessions.php config file, you can increase the lottery number which will sweep inactive sessions:

/*
    |--------------------------------------------------------------------------
    | Session Sweeping Lottery
    |--------------------------------------------------------------------------
    |
    | Some session drivers must manually sweep their storage location to get
    | rid of old sessions from storage. Here are the chances that it will
    | happen on a given request. By default, the odds are 2 out of 100.
    |
    */

    'lottery' => [2, 100],

However, this will slow down your requests if you put a big number ( I am talking about increasing the odds from 2 out of 100 to let's say 20 out 100 ).

Sinnbeck's avatar

@dinni maybe try switching to another session driver. Redis or cookie

Please or to participate in this conversation.