[英]Should session_start always be called?
I noticed that there's a tmp/ folder on my webserver that contains thousands and thousands of session-id files.我注意到我的网络服务器上有一个 tmp/ 文件夹,其中包含成千上万个 session-id 文件。 So I thought it's probably better to only call session_start() when I am actually writing something into the session (login) and then only call it, if there's a logged in user active.
所以我认为最好只在我实际向 session (登录)写入内容时调用 session_start() ,然后仅在有登录用户处于活动状态时才调用它。
I couldn't find too much on the topic (and I'm not sure if what I'm trying to accomplish is possible even), just a couple of people saying that session_start() should always be called.我在这个话题上找不到太多(而且我不确定我想要完成的工作是否可行),只有几个人说 session_start() 应该总是被调用。 Does that make sense?
那有意义吗? And isn't it a performance issue if all these session-ids are stored?
如果存储了所有这些会话 ID,这不是性能问题吗?
So I thought it's probably better to only call session_start() when I am actually writing something into the session (login) and then only call it, if there's a logged in user active.
所以我认为最好只在我实际向 session (登录)写入内容时调用 session_start() ,然后仅在有登录用户处于活动状态时才调用它。
If you set up a login system in any vaguely traditional way that involves sessions, there is no way to tell if you have a logged in user without calling session_start
.如果您以任何涉及会话的模糊传统方式设置登录系统,则如果不调用
session_start
就无法判断您是否有登录用户。
just a couple of people saying that session_start() should always be called.
只有几个人说 session_start() 应该总是被调用。 Does that make sense?
那有意义吗?
Yes.是的。 If you are going to interact with a session — be it to write to the session, or read from it — then call
session_start()
.如果您要与 session 交互——无论是写入 session,还是从中读取——然后调用
session_start()
。
Most websites that deal with login sessions will put a "You are logged in as Bob: click here to logout" or "You are not logged in: click here to log in" message on every page, so most websites will need to call sessions_start()
on every page.大多数处理登录会话的网站都会在每个页面上放置“您以 Bob 身份登录:单击此处注销”或“您未登录:单击此处登录”消息,因此大多数网站需要调用
sessions_start()
在每一页上。
And isn't it a performance issue if all these session-ids are stored?
如果存储了所有这些会话 ID,这不是性能问题吗?
No.不。
It has a performance impact , but that impact is probably negligible.它对性能有影响,但这种影响可能可以忽略不计。 If it becomes a problem, worry about it then.
如果它成为一个问题,然后担心它。
Don't try to solve performance problems you don't have.不要试图解决你没有的性能问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.