dongyinting3179 2017-07-14 00:41
浏览 235
已采纳

如何刷新/ var / lib / php / session /中的旧会话?

I noticed recently that I have a huge number of sessions in there - 1.3M sessions (as determined from ls -l /var/lib/php/session/ | wc -l). My weekly visits are only in the single-digit thousands, so this seems crazy high - I'm assuming it is somehow saving the sessions and never flushing the old ones for some reason.

Are there relevant settings in the php.ini that control these?

  • 写回答

1条回答 默认 最新

  • duaj39673 2017-07-14 00:51
    关注

    Yes, discussion of this can be found in the manual here:

    You want to look at all the session.gc_ settings, as those are the variables that effect how likely it is that garbage collection is running.

    With that said, something is clearly wrong, as it seems like your session files are not being deleted.

    You do need to factor in the session.gc_maxlifetime setting in your php.ini file, as no file will be deleted until that number of seconds since file creation has passed. If your gc_maxlifetime is too long, files will accumulate.

    This script is a recommended cron - oriented command line php script that can be installed and run daily or weekly to run the garbage collector. I would start with that and see what happens.

    There could be permissions issues that are actually preventing the garbage collector from deleting the sessions, so starting with a manual run of this program and seeing what happens to the number of session files would be a good start. If you have php7.1 this is the recommended code from the manual.

    <?php
    // Note: This script should be executed by the same user of web server process.
    
    // Need active session to initialize session data storage access.
    session_start();
    
    // Executes GC immediately
    session_gc();
    
    // Clean up session ID created by session_gc()
    session_destroy();
    ?>
    

    A program for older versions of php that should work in a similar fashion would be:

    <?php
    ini_set('session.gc_probability', '1');
    ini_set('session.gc_divisor', '1');
    session_start();
    session_destroy();
    ?>
    

    The idea here is that you are guaranteeing that the garbage collector will run by making the probability 100% for this script.

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

报告相同问题?

悬赏问题

  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿