Skip to content

Instantly share code, notes, and snippets.

@tayhimself
Last active September 5, 2017 01:11
Show Gist options
  • Save tayhimself/c0049360c92413969af3240d80655164 to your computer and use it in GitHub Desktop.
Save tayhimself/c0049360c92413969af3240d80655164 to your computer and use it in GitHub Desktop.
Symfony session request timeout detect

config.yml :

services:
    mycompany.demobundle.listener.request:
        class: MyCompany\DemoBundle\RequestListener
        arguments: [@router, @security.context]
        tags:
             - { name: kernel.event_listener, event: kernel.request, method: onKernelRequest }

RequestListener

$inactive = 6000; 
$session_life = time() - $request->getSession()->('timeout');
if($session_life > $inactive && $request->isXmlHttpRequest() )
    {  
         $headers['Content-Type'] = 'application/json';
         return new Response(json_encode($data), $status, $headers);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment