Home >Backend Development >PHP Tutorial >How to deal with session saving failure in Laravel 5.4.36

How to deal with session saving failure in Laravel 5.4.36

php中世界最好的语言
php中世界最好的语言Original
2018-05-18 14:40:382243browse

This time I will bring you how to handle the failure to save session in Laravel 5.4.36. What are the precautions for handling the failure to save session in Laravel 5.4.36? Here is the actual combat Let’s take a look at the case.

Points to note when using session

Laravel is a

php framework. When using laravel, you will encounter session usage problems. The default file of session is used at work. Caching, after using it, I found that session()->put("key","values") was not set successfully. Finally, I checked the source code and found that I need to use save()# when using file caching. ## Method can be persisted to the databaseSource code: 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;
 }

Due to the use of file caching, the source code of the write method call: vendor/laravel/framework/src/Illuminate/Session/FileSessionHandler.php

/**
  * {@inheritdoc}
  */
 public function write($sessionId, $data)
 {
  $this->files->put($this->path.'/'.$sessionId, $data, true);
  return true;
 }

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the PHP Chinese website!

Recommended reading:

thinkphp5 migrate Detailed explanation of database migration usage


Detailed explanation of php namespace usage

The above is the detailed content of How to deal with session saving failure in Laravel 5.4.36. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn