Hello !
I would like to clarify about session. Everybody here seems to run this perfectly well but who can explain me the followin:
There is a general code for PHP/MySQL session management:
1
2 <?php
3
4 function open ($save_path, $session_name) {
5 echo "open ($save_path, $session_name)\n";
6 return true;
7 }
8
9 function close() {
10 echo "close\n";
11 return true;
12 }
13
14 function read ($key) {
15 echo "write ($key, $val)\n";
16 return "foo|i:1;";
17 }
18
19 function write ($key, $val) {
20 echo "write ($key, $val)\n";
21 return true;
22 }
23
24 function destroy ($key) {
25 return true;
26 }
27
28 function gc ($maxlifetime) {
29 return true;
30 }
31
32 session_set_save_handler ("open", "close", "read", "write", "destroy", "gc");
33
34 session_start();
35
36 $foo++;
37
38 ?>
Q1. I don't understang what the hell this "foo" is for. Can anybody explain me that ???
Q2. How shall I use the garbage collect function ? The argument for this function is configuration variable '$maxlifetime' but why is this used as an argument for the 'gc' function ? I can't see any usage of this argument in the body of this function ! Moreover - how shall I call this function ? Should I make some "metascript", kind of server-side application periodically calling the 'session_gc' function or is there some kind of background automatism withing PHP, so no need to worry - the server will do this itself ? Can you explicite explain this to me ???
Thank's a lot !
Ziggi
I would like to clarify about session. Everybody here seems to run this perfectly well but who can explain me the followin:
There is a general code for PHP/MySQL session management:
1
2 <?php
3
4 function open ($save_path, $session_name) {
5 echo "open ($save_path, $session_name)\n";
6 return true;
7 }
8
9 function close() {
10 echo "close\n";
11 return true;
12 }
13
14 function read ($key) {
15 echo "write ($key, $val)\n";
16 return "foo|i:1;";
17 }
18
19 function write ($key, $val) {
20 echo "write ($key, $val)\n";
21 return true;
22 }
23
24 function destroy ($key) {
25 return true;
26 }
27
28 function gc ($maxlifetime) {
29 return true;
30 }
31
32 session_set_save_handler ("open", "close", "read", "write", "destroy", "gc");
33
34 session_start();
35
36 $foo++;
37
38 ?>
Q1. I don't understang what the hell this "foo" is for. Can anybody explain me that ???
Q2. How shall I use the garbage collect function ? The argument for this function is configuration variable '$maxlifetime' but why is this used as an argument for the 'gc' function ? I can't see any usage of this argument in the body of this function ! Moreover - how shall I call this function ? Should I make some "metascript", kind of server-side application periodically calling the 'session_gc' function or is there some kind of background automatism withing PHP, so no need to worry - the server will do this itself ? Can you explicite explain this to me ???
Thank's a lot !
Ziggi