Home > Enterprise >  Either session expires in the middle of work or Warning: session_cache_expire(): Session cache expir
Either session expires in the middle of work or Warning: session_cache_expire(): Session cache expir

Time:09-17

Using PHP 8.0.6 on Windows 10 locally I received this error message:

Warning: session_cache_expire(): Session cache expiration cannot be changed when a session is active in C:\path\sessions.php on line 5

I updated the same file on the live Linux server (PHP 8.0.9) and the issue doesn't occur.

The relevant code:

session_cache_expire($session_length);

My first guess is that this might be a Windows specific issue however I just saw that other people accessing the live server were also encountering this issue.

The original intention of this line was that members were being signed out in the middle of their sessions because the expiration date was not being updated with requests from the client computers to the server. I added this line and suddenly the session cookie expiration dates were being updated however this error would randomly start occuring. How do I keep the session alive without this nonsense error occurring?

CodePudding user response:

The documentation (php.net/manual/en/function.session-cache-expire.php) states:

"Thus, you need to call session_cache_expire() for every request (and before session_start() is called)."

I suspect this is your problem, but cannot be certain without seeing more of your code.

  • Related