title: Ddos attacks in symfony2
body: <p>I would like to integrate a script that avoid a DDos attack in symfony project. Althought i have tried to create an event listener to do the work, i haven't succeeded.</p>
  
  <p>Below the created script in symfony2 listener:</p>
  
  <pre><code>public function onKernelRequest(GetResponseEvent $event) {    
      $session = $this-&gt;requestStatck-&gt;getCurrentRequest()-&gt;getSession();
  
      if (!$event-&gt;isMasterRequest()) {
          // don't do anything if it's not the master request
          return;
      }
  
      if($session-&gt;get('last_session_request') &gt; time() - 2 ){
          die('DDos attack');
      }
  
      $session-&gt;set('last_session_request',  time());
  }
  </code></pre>
  
  <p>This one makes me some problems on the page view such as unstyled page, no js,..</p>
  
  <p>I work with the symfony2 version 2.7.7</p>
  
  <p>I look forward to getting solution.</p>
  
  <p>Thank you.</p>