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 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥15 DruidDataSource一直closing
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥50 power BI 从Mysql服务器导入数据,但连接进去后显示表无数据