I have a simple question: how exactly are array variables such as $_SESSION and $_SERVER requested? Are they simply set when the page is requested and remain the same until the page is requested (e.g.
for($i=0, $i<100, ++$i) {
echo $_SERVER['REQUEST_TIME'],'<br/>',$_SESSION['lastActive'],'<hr/>';
}
would only do one request for each variable and post 100 lines) or should I simply bind them to a variable so as to avoid unnecessary server requests, e.g.
$time=$_SERVER['REQUEST_TIME'];
$lastActive=$_SESSION['lastActive'];
for ($i=0, $i<100, ++$i) {
echo $time,'<br/>',$lastActive,'<hr/>';
}
My apologies if this sounds like common sense, but I simply dislike setting extra variables where they can be avoided and thus try to do as much research as possible.
No requests (that is, web requests) are ever made. Even when accessing
$_GETand$_POST, there’s no communication back and forth between the client and the server to get the contents.Also, if you think PHP runs on the client, it doesn’t.
Finally, if you just mean loading: the contents of
$_SERVERwill either be set at the beginning of the script or on first access, depending on yourphp.inisettings.$_SESSIONwill be set when you callsession_start();.