'CodeIgniter session expires randomly

I am using CodeIgniter 4 for my websites, and has the following session settings in the .env file.

app.sessionDriver = 'CodeIgniter\Session\Handlers\DatabaseHandler'
app.sessionCookieName = 'ci_session'
app.sessionExpiration = 86400
app.sessionSavePath = 'ci_sessions'
app.sessionMatchIP = false
app.sessionTimeToUpdate = 300
app.sessionRegenerateDestroy = false

However, the session always expired much earlier and randomly.

I have also try setting sessionExpiration to 0, but this does not solve the issue.

Please help.

Thanks in advance.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source