且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

PHP 会话超时太快

更新时间:2023-12-04 19:52:46

随机过期是多个应用程序共享会话数据目录的典型症状:session.gc_maxlifetime 时间最短的可能是从其他应用程序中删除数据.原因:

Random expiration is a classical symptom of session data directory shared by several applications: the one with the shortest session.gc_maxlifetime time is likely to remove data from other applications. The reason:

  1. PHP 默认将会话文件存储在系统临时目录中.
  2. 内置文件处理程序不会跟踪谁拥有哪个会话文件(它只是将文件名与会话 ID 匹配):

  1. PHP stores session files in the system temporary directory by default.
  2. The builtin file handler doesn't track who owns what session file (it just matches file name with session ID):

我的建议是您为您的应用程序配置一个私有的自定义会话目录.这可以通过 session_save_path() 函数 或设置 session.save_path 配置指令.有关如何在您自己的代码库中执行此操作的准确详细信息,请查看您的框架文档.

My advice is that you configure a private custom session directory for your application. That can be done with the session_save_path() function or setting the session.save_path configuration directive. Please check your framework's documentation for the precise details on how to do it in your own codebase.