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:

     $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.

1 Answer 1


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.

  • The APC cache will either have to copy the array contents from cache to the PHP process requesting it or use serialization, either will have similar or more overhead than building the array normally
    – Esailija
    Jul 31, 2013 at 23:41
  • @Esailija APC is only recommended for variable-level caching in this answer if the overhead for generating the structure is notable. E.g., a time-consuming query or service call.
    – svidgen
    Aug 1, 2013 at 1:18
  • But, thanks for noting the reason explicitly! Knowing what your "overhead" compares to helps define whether it's "notable." that said, if there's any question about whether to use APC (or similar) to address the issue, a comparative benchmark should be performed.
    – svidgen
    Aug 1, 2013 at 1:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.