doupo2633 2013-10-07 18:30
浏览 105
已采纳

在页面加载时重置$ _SESSION到期计时器

ini_set('session.cookie_lifetime', 259200);
ini_set('session.gc_maxlifetime', 259200);
session_start();

I have the above bit of code included on every single page on my site. I want to keep the user logged in for three days after logging in, but if they visit the site before the expiry date, it keeps them alive for three more days. Basically, the session is kept alive three days from when they leave the site (and if they don't return within those three days).

I've noticed, however, that sessions are kept alive for about a day and then die despite the ini_set I have above. I considered that perhaps it was my webhost's php.ini, but it also does this on my local machine.

Is there some other ini_set call I can do to get my desired effect? These don't seem to work, although they do keep it alive for one day.

  • 写回答

1条回答 默认 最新

  • doucang6739 2013-10-07 18:48
    关注

    As the size of a session gets larger, you'll run into various quirks though: not sure about current version, but PHP 5.1.x was loading the whole session into memory at session_start(); with a 20 MB session and 50 concurrent users, your scripts start to be severely limited by disk access speeds (a.k.a. "script startup is slow as molasses" - the sessions alone are hogging a GB of RAM, you definitely don't want your server to start swapping out); in the end, we dedicated a box to keep as many sessions as possible in its RAM, and the frontend boxes accessed them over NFS (although it helped in our case, this may be overkill for you).

    Note that for many concurrent users and session storage on disk, the number of session temporary files may cause problems with filesystem limits (e.g. how many files can be in one directory), or other limits (we once found the hard way that a box was configured to only allow 4096 open files at the same time). None of this is really session-specific, but can be triggered by session handling.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

悬赏问题

  • ¥15 FPGA芯片60进制计数器
  • ¥15 前端js怎么实现word的.doc后缀文件在线预览
  • ¥20 macmin m 4连接iPad
  • ¥15 DBIF_REPO_SQL_ERROR
  • ¥15 根据历年月数据,用Stata预测未来六个月汇率
  • ¥15 DevEco studio开发工具 真机联调找不到手机设备
  • ¥15 请教前后端分离的问题
  • ¥100 冷钱包突然失效,急寻解决方案
  • ¥15 下载honeyd时报错 configure: error: you need to instal a more recent version of libdnet
  • ¥15 距离软磁铁一定距离的磁感应强度大小怎么求
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部