/** * Store the session payload in storage. * * This method will be called automatically at the end of the request. * * @return void */ public function save() { $this->session['last_activity'] = time(); // Session flash data is only available during the request in which it // was flashed and the following request. We will age the data so that // it expires at the end of the user's next request. $this->age(); $config = Config::get('session'); // The responsibility of actually storing the session information in // persistent storage is delegated to the driver instance being used // by the session payload. // // This allows us to keep the payload very generic, while moving the // platform or storage mechanism code into the specialized drivers, // keeping our code very dry and organized. $this->driver->save($this->session, $config, $this->exists); // Next we'll write out the session cookie. This cookie contains the // ID of the session, and will be used to determine the owner of the // session on the user's subsequent requests to the application. $this->cookie($config); // Some session drivers implement the Sweeper interface meaning that // they must clean up expired sessions manually. If the driver is a // sweeper, we'll calculate if we need to run garbage collection. $sweepage = $config['sweepage']; if ($this->driver instanceof Sweeper and mt_rand(1, $sweepage[1]) <= $sweepage[0]) { $this->driver->sweep(time() - $config['lifetime'] * 60); } }
/** * Store the session payload in storage. * * The activity timestamp will be set, the flash data will be aged, and the * session cookie will be written. The driver given when the session payload * was constructed will be used to persist the session to storage. * * If the session's driver is a sweeper implementation, garbage collection * may be performed based on the probabilities set in the "sweepage" option * in the session configuration file. * * @return void */ public function save() { $this->session['last_activity'] = time(); $this->age(); $config = Config::$items['session']; $this->driver->save($this->session, $config, $this->exists); $this->cookie(); // Some session drivers implement the Sweeper interface, meaning that they // must clean up expired sessions manually. If the driver is a sweeper, we // need to determine if garbage collection should be run for the request. // Since garbage collection can be expensive, the probability of it // occuring is controlled by the "sweepage" configuration option. $sweepage = $config['sweepage']; if ($this->driver instanceof Sweeper and mt_rand(1, $sweepage[1]) <= $sweepage[0]) { $this->driver->sweep(time() - $config['lifetime'] * 60); } }
/** * Clean up expired sessions. * * If the session driver is a sweeper, it must clean up expired sessions * from time to time. This method triggers garbage collection. * * @return void */ public function sweep() { if ($this->driver instanceof Sweeper) { $this->driver->sweep(time() - Config::get('session.lifetime') * 60); } }