If I have a file config.php with some configurations in some variables and in some page I include this file, each time the variables will be loaded again in the memory of the server?
I think the answer is yes, but I’m not sure, I don’t know to much of the PHP lifecycle. I don’t know if I made myself clear, so here is an example. Suppose, I have the config.php file as:
<?php
$databaseConfig = array();
/* Sets the configurations inside the array */
?>
Then my index.php page includes the file config.php. Each time the index is loaded the $databaseConfig array will be loaded into memory or just the first time and so when the page is requested again it doesn’t need to load it again? I really think that since PHP is stateless it will load again each time.
The file is reloaded and re-parsed at each request. (That may or may not mean it’s loaded from disk.) Installing something like APC generally ensures you don’t hit the disk or take the parsing hit each time.
The code is re-executed entirely with each request, even if the bytecodes are cached. So, any variable, including $databaseConfig
, is rebuilt with each request. If it comes with notable overhead, you can also use something like APC to cache it in memory.
3