SoFunction
Updated on 2025-03-10

php prompts Failed to write session data error solution

This article analyzes the solution to the error in php prompting Failed to write session data in more detail. Share it for your reference. The specific methods are 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:

Copy the codeThe code is as follows:
session.save_path = "D:/phprun/tmp"

This is a custom folder. The pointing error caused by the system. The system will not appear by default. It is prompted that sometimes the directory may not have permission to write, so you can just give permission.

Due to PHP's working mechanism, it does not have a daemon thread to regularly scan the Session information and determine whether it is invalid. When a valid request occurs, PHP will decide whether to enable a GC based on the values ​​of the global variables session.gc_probability and session.gc_divisor. By default, session.gc_probability=1, session.gc_divisor =100, which means there is a 1% chance of starting GC (that is, only one of the 100 requests will be started with a request in 100).

The job of the PHP garbage collection mechanism is to scan all Session information, subtract the last modified time of the session using 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 deleted.

However, if your web server has multiple sites and multiple sites, GC may experience unexpected results when processing sessions. The reason is that when GC works, it will not distinguish between sessions of different sites.

I hope this article will be helpful to everyone's PHP programming.