I came from Desktop development and I am used to see my application in the computer's memory until it is terminated by the user. But with PHP we have to rebuild all the environment (classes, objects, database connections etc.) every time a new page is requested to the server. We store a few variables in the $_SESSION
array to keep the user logged if he/she is authenticated.
Is it a good idea if after the user authentication, I put the application
object (and every other objects the application created into the current session so the interpreter does not need to reload everything on every request? If it is a good idea, is it only a good if my server is dedicated?
I can't think that it wont make the response faster, and also less memory consumer.
<?php
// if user and password match:
session_start()
$_SESSION['Application'] = new TApplication('index/index');
$_SESSION['Application']->SetUser($userName);
$_SESSION['Application']->ConfigureUserPermissions;
$_SESSION['Application']->RUN;
<?php
// any request after user is logged and application is set:
session_start()
if (isSet($_SESSION['Application']) && (!$_SESSION['Application']->GetUser = null))
{
$_SESSION['Application']->ExecuteAction($_GET['url']);
}
I want to know if it is:
- Possible?
- A server memory killer?
- Faster then rebuild the app by reading all
PHP
files from myMVC
? - Reliable approach?