Home >Backend Development >PHP Tutorial >How to deal with session saving failure in Laravel 5.4.36
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 aphp 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 usageDetailed explanation of php namespace usageThe 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!