简体   繁体   English

可以回应SESSION的大小吗?

[英]Can echo size of SESSION?

I dont know if my sessions are too big. 我不知道我的会话是否太大了。 Is there a way to see the size of a session. 有没有办法看到会话的大小。 Thanks, Rahul 谢谢,拉胡尔

$size_of_session_estimate = strlen( serialize( $_SESSION ) );

Now, this is just an estimate, as the serialize handler is not used to serialize sessions, but it also won't be too far off. 现在,这只是一个估计,因为序列化处理程序用于序列化会话,但它也不会太远。

That being said, unless you're storing a silly amount of data in the session, you probably don't need to worry about this. 话虽这么说,除非你在会话中存储了大量的数据,否则你可能不需要担心这一点。

If you are using Apache, take a look into your APACHE_ROOT/tmp folder and look for files named sess_*********** . 如果您使用的是Apache,请查看您的APACHE_ROOT/tmp文件夹并查找名为sess_***********文件。

Otherwise take the script from here and call it using array_size($_SESSION) . 否则从这里获取脚本并使用array_size($_SESSION)调用它。 This might differ slightly from the exact value (depending on compression/optimizations done by your PHP module). 这可能与确切的值略有不同(取决于PHP模块执行的压缩/优化)。

This: 这个:

echo strlen(session_encode());

will give you the amount of disk space used by $_SESSION (assuming session.save_handler is the default value files ), since session_encode() returns a string identical to the string stored in the session file. 将为您提供$ _SESSION使用的磁盘空间量(假设session.save_handler是默认值文件 ),因为session_encode()返回与存储在会话文件中的字符串相同的字符串。

It will also give a better indication of the amount of memory used, since session_encode() adds less metadata than serialize() . 它还可以更好地指示所使用的内存量,因为session_encode()添加的元数据少于serialize()

On a default Apache setup, you can see the session data as stored on disk with: 在默认的Apache设置中,您可以看到存储在磁盘上的会话数据:

session_write_close();
echo file_get_contents(sys_get_temp_dir() . 'sess_' . session_id());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM