doulang7699 2014-12-29 03:22
浏览 12
已采纳

PHP客户垃圾收集

I have made a dummy session handler class while learning how sessions in php work.

I have the normal:

open, close, read, write, destroy and gc functions inside this class.

I have passed the class to a handler (when the class is created in has one parameter which is the db connection):

$handler = new Session($testdb);
session_set_save_handler(
  array($handler,'open'),
  array($handler,'close'),
  array($handler,'read'),
  array($handler,'write'),
  array($handler,'destroy'),
  array($handler,'gc')
);
session_start();

All of the functions inside this class have worked well - passing the data back and forth to the custom database as planned, accept the garbage collection. the gc function does not seem to want to play ball. When manually called it will work fine but php never seems to call it.

code block of the gc function:

  Public function gc($expire)
 { 
    $SessionInfo = new Delete($this->WebSite,array($expire),
    "DELETE FROM sessions
    WHERE DATE_ADD(LastAccessed, INTERVAL $expire SECOND) < NOW()
    ");
    echo '<H1>BIG LETTERS</H1>'; // HTML shout out if function is called //
    return true;
 }

I know there is a 1% chance on each session_start() that this is called but i have adjusted the % chance in my php.ini file so as to increase the chances to more 50% and tried several times to get this to actual be used. The fact that the function works fine when manually called and the fact that the other functions in the class work as they should ... leads me slighly stuck ... any ideas?

  • 写回答

1条回答 默认 最新

  • dongyan1548 2014-12-30 02:58
    关注

    Fixed.

    There were 2 problems:

    1: In the function my query should have taken a "?" in the INTERVAL $expire SECOND line (so INTERVAL ? SECOND) ... I am still not sure HOW it was working at all when i spotted this. The class uses a PDO statement which should throw an error when a variable is inputted ... but yay thats another matter.

    2: php.ini file was showing an incorrect probability chance for garbage collection ... likely down to previous editting on my part. (MAIN REASON)

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

报告相同问题?

悬赏问题

  • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
  • ¥20 关于URL获取的参数,无法执行二选一查询
  • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
  • ¥15 marlin编译错误,如何解决?
  • ¥15 有偿四位数,节约算法和扫描算法
  • ¥15 VUE项目怎么运行,系统打不开
  • ¥50 pointpillars等目标检测算法怎么融合注意力机制
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集