laravel是一款php框架了,在使用laravel时会碰到session使用问题,工作中使用的是session默认的文件缓存,在使用过发现  session()->put("key","values") 没有设置成功,最后翻源码发现是使用文件缓存时候需要使用save() 方法才能持久化到数据库中。源码:vendor/laravel/framework/src/Illuminate/Session/Store.php 
 
 /**
  * Save the session data to storage.
  *
  * @return bool
  */
 public function save()
 {
  $this->ageFlashData();
  $this->handler->write($this->getId(), $this->prepareForStorage(
   serialize($this->attributes)
  ));
  $this->started = false;
 }由于使用文件缓存 因此write方法调用的源码:vendor/laravel/framework/src/Illuminate/Session/FileSessionHandler.php 
 
 /**
  * {@inheritdoc}
  */
 public function write($sessionId, $data)
 {
  $this->files->put($this->path.'/'.$sessionId, $data, true);
  return true;
 } |