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

leostereo's avatar

Session lifetime question.

Hi guys , Im learning about sessions in laravel. I declare these routes:

Route::get('session/get','SessionController@accessSessionData');
Route::get('session/set','SessionController@storeSessionData');

One to store and other to retrieve the session key. and this is the controller:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class SessionController extends Controller
{

   public function accessSessionData(Request $request) {
        $value = $request->session()->get('key');
	return $value;
        //
    }
   public function storeSessionData(Request $request) {
        $value = $request->session()->put('key',date("Y-m-d H:i:s"));

        //
    }
}

Problem is that ... after first session->put, the stored key is never cleared. According to my .env , session lifetime is 120 (secconds I suppose).

[root@localhost api_chat]# grep SESSION .env
SESSION_DRIVER=file
SESSION_LIFETIME=120

But my key still there , allways calling at http://10.1.1.50/api_chat/public/index.php/api/session/get it returns for example: 2020-03-23 14:32:21 Shouldn`t key value be cleared autmatically after 120 seconds ?

Any thought would be wellcome. Regards. Leandro.

0 likes
2 replies
leostereo's avatar

Dear Sti3bas , thanks for the response. Why do you consider better to use cache instead of session ? (never worked with any of them. My project is to build a telegram chat aplication , I will keep track fo conversation. I appreciate your advice on this. Leandro.

Please or to participate in this conversation.