每个会话调用是对服务器的单独调用 [英] is each session call is separate call to server

查看:42
本文介绍了每个会话调用是对服务器的单独调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

记住服务器负载,我想知道对会话的每次调用是否是对服务器的单独调用,这会增加服务器负载吗?让我稍微解释一下.假设在每个php页面中,我必须设置10个会话数据并且必须像这样调用10个会话数据:

Keeping in mind of server load, I want to know whether each call to session is a separate call to server which increases server load? Let me explain it little bit. Suppose in each php page, I have to set 10 session data and have to call 10 session data also like this:

$_SESSION['a']=1;
$_SESSION['b']=2;
$_SESSION['c']=3;
$_SESSION['d']=4;
$_SESSION['e']=5;
$_SESSION['f']=6;
$_SESSION['g']=7;
$_SESSION['h']=8;
$_SESSION['i']=9;
$_SESSION['j']=10;

echo $_SESSION['a'];
echo $_SESSION['b'];
echo $_SESSION['c'];
echo $_SESSION['d'];
echo $_SESSION['e'];
echo $_SESSION['f'];
echo $_SESSION['g'];
echo $_SESSION['h'];
echo $_SESSION['i'];
echo $_SESSION['j'];

设置以上10个会话并输出相同,这些是20个单独调用服务器还是通过session_start(),在页面加载时一次性加载整个会话数据?

setting of above 10 sessions and outputting the same, will these be 20 separate calls to server or by session_start(), whole session data is loaded at once during page loading?

还想知道如何在会话中存储多维关联数组?假设我想像这样设置上面的10个会话数据:

Also want to know how to store multidimensional associative array in session? Suppose I want to set the above 10 session data like this:

$_SESSION['mydata']=array(
a=>1,
b=>2,
c=>3,
d=>4,
e=>5,
f=>6,
g=>7,
h=>8,
i=>9,
j=>10
)

echo $_SESSION['mydata']['a'];

通过上面的例子,如果每个会话调用都是对服务器的单独调用,我可以减少服务器负载.

By the above example I can reduce server loads if each session call is separate call to server.

有人告诉我设置和获取会话数据时发生了什么吗?

Anyone clear me what's going on when we set and get session data?

推荐答案

这是一个会话的细分

  • session_start(); 要么在硬盘驱动器上创建一个会话文件,要么访问一个已经存在的会话文件.它是一个序列化的数组
  • 这个数组被加载到内存中并在内存中被操作,直到脚本完成执行或者你可以强制它使用session_write_close()
  • 重写文件
  • session_start(); either creates a session file on the hard drive or accesses one if it is already there. It is a serialized array
  • This array gets loaded into memory and is manipulated within memory until the script finishes executing or you can force it to re-write the file with session_write_close()

您可以在开始会话后添加/删除任意数量的数据,因为这与操作数组没有什么不同.

You can add/remove as much data as you wish after you have started the session because it is no different than manipulating an array.

繁重的工作在 session_startsession_write_close 完成,因为那是 PHP 真正需要访问硬盘的时间

The heavy lifting is done at session_start and session_write_close because that is when PHP actually has to access the hard drive

理论上每个用户可以在 FAT32 服务器上拥有一个 4GB 的会话文件,或者在 NTFS 服务器上拥有更大的会话文件,但我相信您可以想象会出现可怕的性能问题.

In theory each user can have a 4GB session file on a FAT32 server, or larger on NTFS server, but I am sure you can imagine the horrendous performance issues that would arise.

这篇关于每个会话调用是对服务器的单独调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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