3. What are session and variables

[<<<] [>>>]

=abstract Some description on what is a session and what are session and MT variables. =end

Formally a session is the series of consecutive execution of ScriptBasic scripts that belong to the same calculation. Typically this is the series of web script executions that serve the same client.

When a client meets the web server the first time the program creates a new session and when the user goes on with the web application the same session information is used. The session ID is usually sent to the client in HTTP cookie and when the browser sends the cookie back the server application remembers that this client is the same as the one before. What the application really remembers is that state of the transaction the user performed in the session. The tipical example is the consumer basket in an eShop. The user behind the browser puts several things into the basket while shopping and the application has to remember what is in the basket.

Conventional CGI applications usually store the session information in plain text files or in database. That is usually a slow solution unless you need to store these information for a longer period. But session state is usually not stored for long time.

When a browser first comes to the site a new session is created calling NewSessionId. Later when the user gets to the next page the session id is sent from the browser and the application checks that the session really exists calling CheckSessionId and if it exists it tells the MT extension module calling SetSessionID that the actual session served by the currently running interpreter thread is this.

To store a value that belongs to that session the application can call SetSessionVariable and to retrieve the value call GetSessionVariable. Session variables are kept in memory and can be reached extremely fast. They are available until the session is deleted calling DeleteSession.

There can be not two interpreter threads running concurrently accessing the same session data. Each session has its own variable set and in case a session has a variable named "BASKET" this has nothing to do with the other sessions variable of the same name.

MT variables on the other hand are shared by all sessions. An MT variable has a name, and in case a session modifies the MT variable named "BASKET" the other session looking at the MT variable "BASKET" will see the changed value. MT variables are global among the sessions.

When accessing an MT variable the variable can not be accesses by other interpreter threads. Thus there is no chance that an MT variable gets up messed. What is more a program may decide to lock an MT variable preventing other programs to alter it or even to read its value until the variable is unlocked. For this the program should call LockWrite, LockRead and to unlock UnlockWrite, UnlockRead


[<<<] [>>>]