How to deal with session saving failure in Laravel 5.4.36

php中世界最好的语言
Release: 2023-03-26 16:24:02
Original
2181 people have browsed it

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;
 }
Copy after login

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;
 }
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!