In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "how session exists on the server side". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how session exists on the server side".
By default, php saves the session in the / tmp directory, and the file name looks like this: sess_01aab840166fd1dc253e3b4a3f0b8381. Each file corresponds to a session (session).
More/tmp/sess_01aab840166fd1dc253e3b4a3f0b8381
Username | SRV 9: "phpzixue.cn"; admin | Svv 1: "0"
# variable name | Type: length: value
Delete the session file here, which means that the corresponding session is invalid.
How does session exist on the client side (usually a browser)?
Session is on the browser side, you only need to save sessionID (the only ID generated by the server side). There are two ways to save it: in cookie and in url. If you save sessionID in cookie, you can see that there is a PHPSESID variable in the browser's cookie. If it is passed by URL, you can see something like:
URL of index.php?PHPSESID=01aab840166fd1dc253e3b4a3f0b8381. (use session.use_cookies to control which method is used on the server side)
On the server side, how does php determine whether the session file is out of date
If the "last modification time" to "now" exceeds gc_maxlifetime (default is 1440) seconds, the session file is considered to have expired, and the next time session reclaims, if the file has not been changed, the session file will be deleted (session will expire).
To put it simply, if I log in to a website and do not operate within 1440 seconds (the default), then the corresponding session is considered to have expired.
So, changing the gc_maxlifetime variable in the php.ini file can extend the expiration time of session: (for example, we change the expiration time to 86400 seconds)
Session.gc_maxlifetime=86400
Then, restart your web service (usually apache).
Note: the session expiration in php5 uses the recycling mechanism. The time set here is 86400 seconds, and if the session has not been modified within 86400 seconds, it will really be deleted the next time it is "recycled".
When does session "recycling" occur?
By default, there is a 100% probability of recycling for every php request, so it may be simply understood as "one for every 100 php requests." This probability is controlled by the following parameters
# probability is gc_probability/gc_divisor
Session.gc_probability=1
Session.gc_divisor=100
Note 1: suppose this is the case of gc_maxlifetime=120, if the last modification time of a session file is 120 seconds, then the session is still valid before the next collection (the probability of 100%).
Note 2: if your session uses session.save_path to save session,session recycling elsewhere, it may not automatically process out-of-date session files. In this case, you need to delete expired session:cd/path/to/sessions;find-cmin+24 manually (or crontab) regularly | xargsrm
Some special circumstances
Because the recycling mechanism checks the "last modification time" of the file, if a session is active but the content of the session has not changed, then the corresponding session file has not changed, and the recycling mechanism will delete it as a session that has not been active for a long time. We don't want to see this, and we can solve this problem by adding the following simple code:
If (! isset ($_ SESSION ['last_access']) | | (time ()-$_ SESSION [' last_access']) > 60)
$_ SESSION ['last_access'] = time ()
? >
The code will try to modify the session every 60 seconds.
Thank you for your reading, the above is the content of "how session exists on the server side". After the study of this article, I believe you have a deeper understanding of how session exists on the server side, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.