1

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.

Zanon
3292 gold badges3 silver badges16 bronze badges
asked Jul 31, 2013 at 19:12

1 Answer 1

3

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.

answered Jul 31, 2013 at 19:33
3
  • 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 Commented 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. Commented 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. Commented Aug 1, 2013 at 1:22

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.