Home >Backend Development >PHP Tutorial >PHP prompts Failed to write session data error solution, failedsession_PHP tutorial
This article analyzes in detail the solution to the PHP prompt Failed to write session data error. Share it with everyone for your reference. The specific method is as follows:
1. Question:
Prompt message: Warning: Failed to write session data (files). Please verify that the current setting of session.save_path is correct () in Unknown on line 0
2. Solution:
The code is as follows:
This is caused by a custom folder pointing error. The system will not appear by default. Sometimes, the prompt may be that the directory does not have write permissions, so everyone can just give permissions.
Due to the working mechanism of PHP, it does not have a daemon thread to regularly scan Session information and determine whether it is invalid. When a valid request occurs, PHP will based on the values of the global variables session.gc_probability and session.gc_divisor, To decide whether to enable a GC, by default, session.gc_probability=1, session.gc_divisor =100 means there is a 1% possibility of starting a GC (that is, only one gc in 100 requests will be accompanied by 100 Started by a request).
The job of the PHP garbage collection mechanism is to scan all Session information, subtract the last modification time of the session from the current time, and compare it with the session.gc_maxlifetime parameter. If the survival time exceeds gc_maxlifetime (default 24 minutes), the session will be delete.
However, if your web server has multiple sites, unexpected results may occur when GC processes sessions at multiple sites. The reason is: when GC is working, it does not distinguish between sessions of different sites.
I hope this article will be helpful to everyone’s PHP programming design.