PHP垃圾收集说明 [英] PHP Garbage Collection clarification

查看:51
本文介绍了PHP垃圾收集说明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从PHP手册中,session.gc_probability和session.gc_divisor声明gc将基于该概率发生.我明白了.

From the PHP manual, session.gc_probability and session.gc_divisor state that gc will occur based on this probability. I get that.

我不清楚的是,这种可能性是基于会话还是整个会话.

What I'm not clear on is whether this probability is on a session by session basis or overall.

因此,如果我发生GC的可能性为1%(1/100),这是否意味着如果一个会话持续扩展,那么每次有1%的变化都会清理特定的会话?还是这意味着所有现有会话(以及新会话)中有1%会为所有其他现有会话触发GC?

So if my probability is 1% (1/100) that GC will occur, does that mean that if one session keeps getting extended, each time there is a 1% change that specific session will be cleaned up? Or does this mean that 1% of all existing sessions (as well as new ones) will trigger GC for all other existing sessions?

我很确定是后者,我只是想确定一下.

I'm pretty sure it's the latter, I just want to make sure.

这个问题的目的是,我希望用户在我们的网站上进行长期的会议(6个月).如果所有会话中有1%触发了GC,那么这实际上消除了进行该长期会话的目的,因为GC最终每隔一两个小时就会发生一次.

The purpose of this question is that on our site, I want users to have long-term sessions (6 months). If 1% of all sessions trigger GC, then that effectively removes the purpose of having that long-term session, as GC will end up occurring every hour or two.

推荐答案

每次执行PHP脚本并启动会话时,都有可能会扫过会话文件夹杀死旧会话.

Every time a PHP script is executes and starts session there is a probability that it will sweep through the session folder killing off old session.

Cleanup将仅删除在特定时间内未访问的会话.但是,PHP不保证该会话将在该时间内被销毁.

Cleanup will only delete sessions which were not accessed within a certain time. However PHP does not guarantee that the session WILL be destroyed within that time.

您的长期会话策略应该可以正常工作,但是您可能希望将1%降低到0.1%左右

Your long-term session strategy should work just fine, but you might want to reduce 1% to something like 0.1%

要注意的另一件事是,操作系统可能会在重新引导期间清理您的/tmp文件夹,因此即使PHP无法执行此操作.

Another thing to look out for is that operating system might clean up your /tmp folder during reboot so even if PHP won't do it.

这篇关于PHP垃圾收集说明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆