How does PHP handle variables in RAM?

I am curious how PHP handles variables in memory? If I have 100 constants or variables that contain values ​​related to my application, and not for each user, such as the site name, version number, such things that all users have the same value.

Will PHP put these 100 variables in ram 100 times if 100 users hit the page at the same time? Or does it somehow only save the value in RAM 1 time, and all users support it?

+3
source share
3 answers

You can experiment with memory_get_usage()to control how memory is processed in response to certain declarations. For example, I worked on the following:

echo memory_get_usage(); // 84944
$var = "foo";
echo memory_get_usage(); // 85072
unset($var);
echo memory_get_usage(); // 85096

Comparison with storage in $_SESSION:

echo memory_get_usage(); // 85416
$_SESSION['var'] = "foo";
echo memory_get_usage(); // 85568
unset($_SESSION['var']);
echo memory_get_usage(); // 85584
+1
source

If the variable is just $, then yes, 100 variables will be multiplied by 100 users. Even when we count the session storage, during the execution of the request, these variables are also stored in memory in $ _SESSION.

, , , , , ; PHP- , . PHP , PHP (mod_php vs CGI/FastCGI), , .

, 100 , PHP script, PHP , , . , , ( ), , script . , -.

+2

Only pages of code are implicitly shared between processes. Data is separate for processes and aggregated for threads unless explicitly redefined, for example. Shared SysV memory.

+1
source

Source: https://habr.com/ru/post/1728797/


All Articles