I need help understanding the inner workings of PHP.
Remember, in the old days we used TSR (Terminate and stay resident) (Pre-windows era) routines to write? As soon as this program is executed, it will remain in memory and can be re-executed using the hotkey (the alt- or ctrl-key key combination).
I want to use a similar concept in web server / applications. Let's say I have common_functions.php, which consists of common functions (such as Generate_City_Combo () or Check_Permission () or Generate_User_Permission_list () or the like) for all web applications running on this apache / php server.
In all modules or applications php files I can write:
require_once (common_functions.php);
which will include this shared file in all modules and applications and works fine.
My question is: how does php handle this internally?
Let's say I have: Two apps, AppOne and AppTwo.
There are two menu options in AppOne: AppOne_Menu_PQR and AppOne_Menu_XYZ
AppTwo has two menu options: AppTwo_Menu_ABC and APPTwo_Menu_DEF
All four menu items call functions {for example, Generate_City_Combo () or Check_Permission () or Generate_User_Permission_list ()} from common_functions.php
Now, consider the following scenarios: A) User XXX logs in and clicks on AppOne_Menu_PQR from his personalized dashboard, then looks at all screens and instructions. This is a series of requests for 8-10 pages (screens), and it is interactive. After that, user XXX clicks on AppTwo_Menu_DEF from his personalized dashboard and again, as before, he views all screens and instructions (about 8-10 pages / screens). Then user XXX disconnects.
B) User XXX logs in and does everything that is mentioned in scenario A. At the same time, user YYY also logs in (from some other client machine) and performs the same actions mentioned in scenario A.
For scenario A, this is the same session. For scenario B, there are two different sessions.
Suppose all menu options call Generate_User_Permission_list () and Generate_Footer (), or many menu options call Generate_City_Combo ().
So how many times did PHP execute / enable common_functions.php on the page request? per session? or to start / end PHP? My understanding - common_functions.php will be executed after EVERY page of request / loop / load / screen, right? In principle, once for each interaction.
Remember that functions such as Generate_City_Combo () or Generate_Footer () produce the same output or do the same regardless of who or when is calling.
I would like to limit this once at startup and termination of the application.
These are just examples. My actual problem is much harder and harder. In my applications, I would just like to call Application_Startup () procedures only once, which will create an ideal environment (for example, all search and reference data structures, read-only data, security matrix, menu options, context-sensitive business execution logic, etc. d ..). After that, all requests arriving at the server should not waste time or resources on creating an environment, but can instantly refer to an "already created environment".
Is this something possible in PHP? How? Could you point me somewhere or some books that explain the inner workings of PHP?
Thanks in advance.