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.

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

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

    ini_set('session.gc_probability', '1');
    ini_set('session.gc_divisor', '1');

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

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



    • ¥40 找同学帮敲Python代码
    • ¥15 MYSQL 订单的商品明细重复计算问题
    • ¥15 微信实时共享位置修改
    • ¥100 TG的session协议号转成直登号号后客户端登录几分钟后自动退出设备
    • ¥50 共模反馈回路的小信号增益
    • ¥15 arduino ssd1306函数与tone函数放歌代码不兼容问题
    • ¥70 0.96版本hbase的row_key里含有双引号,无法deleteall
    • ¥15 诊断性META分析合并效能的检验
    • ¥15 请问abb根据色块判断奇偶数并根据批次号放入仓储
    • ¥66 开发PC客户端一定也要开发上位机吗?