dongyinting3179 2017-07-13 16: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-13 16: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.

    展开全部

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

报告相同问题?

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

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

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

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

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

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

客服 返回
顶部