PHP 如何处理 RAM 中的变量? [英] How does PHP handle variables in RAM?

查看:49
本文介绍了PHP 如何处理 RAM 中的变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很好奇 PHP 如何处理内存中的变量?如果我有 100 个常量或变量集来保存与我的应用程序相关的值,而不是基于每个用户的值,例如站点名称、版本号等,所有用户都具有相同的值.

I am curious how PHP handles variables in memory? If I have 100 constants or variables set that hold values related to my application and not on a per user basis, like site name, version number, things like that, which all users have the same value.

如果 100 个用户同时点击页面,PHP 会将这 100 个变量放入 ram 100 次吗?或者它是否以某种方式只将值存储在 RAM 中 1 次并且所有用户都以此为食?

Will PHP put these 100 variables into ram 100 times if 100 users are hitting the page at the same time? Or does it somehow only store the value in RAM 1 time and all users feed off of that?

推荐答案

您可以尝试使用 memory_get_usage() 监控内存是如何处理以响应某些声明的.例如,我做了以下工作:

You could experiment with memory_get_usage() to monitor how memory is being handled in response to certain declarations. For instance, I worked up the following:

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

与存储在 $_SESSION 中的比较:

Comparing to storing in $_SESSION:

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

这篇关于PHP 如何处理 RAM 中的变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆