I'm curious to know exactly when the session text file is created? An easy and surface level answer to that would probably be,.. well, when you use session_start(). But is it? Could it be all the way at the end when the php script ends?
What makes me think that it may be at the end is that I know PHP would not write to the session file everytime you make a change to a session variables while the execution of the page goes on. For example, if you got something like $_SESSION['x'] = $_SESSION['x'] + 1;
in a loop, the session file does NOT get modified at each and every iteration of the loop. Only when the PHP scripts is done, then the PHP engine makes a change into the file, to store the final value of the $_SESSION['x']
.
With the same taken of logic, I see no reason for PHP engine to create a file as soon as you call the session_start. It could just delay the process.
What that entails is this;
I can start a session with session_start()
, set a few session variables, toss them around within functions, using them as globals, and at the end of script, I unset them, and destroy the session and as a result, I assume NO SESSION FILE IS CREATED, thus no overhead associated with creating the session text files is experienced.
I would like to hear your insights in this.
My purpose is to explore the possibilities of using session variables strictly as a temporary place holder to pass global variables left and right - without dealing with file I/O. In fact, I do not need those variables in the next page at all.
In this case, could sessions prove faster than using globals within functions?