gpt4 book ai didi

php - 什么是 PHP 共享内存(mm,--with-mm) session 模块?

转载 作者:行者123 更新时间:2023-12-02 09:37:23 29 4
gpt4 key购买 nike

什么是 PHP 共享内存分配(mmcompiled --with-mm) session 模块?

你用过吗?你测试过吗?效果好吗?你有 session 锁定问题吗?

使用文件或自定义 session 处理程序(如数据库)时,很容易查看 session 数据的内容,但是是否可以使用此模块查看 session 数据?想要查看 session 数据的个人原因是 (1) 测试 PHP 垃圾收集是否正常工作,以及 (2) 确保它不会占用所有系统内存。

我认为它曾经是一个单独的(PECL?Zend?)扩展,但现在它是核心。

将其编译成 PHP 二进制文件的唯一要求是 OSSP mm headers ,这是一个小的 ~330k 下载。

 $ ./configure --help

// --with-mm=DIR SESSION: Include mm support for session storage

我能找到的唯一信息来自 2006 年的一个留言板帖子,其中引用了一个现已丢失的 Zend session tutorial page [404]。 ,作者引用了其中的一段话:

If you need higher performance, the mm module is a viable alternative; it stores the data in shared memory and is therefore not limited by the hardware I/O system.



我知道其中两个是 limitations :

(1) Note that the session storage module for mm does not guarantee that concurrent accesses to the same session are properly locked. It might be more appropriate to use a shared memory based filesystem (such as tmpfs on Solaris/Linux, or /dev/md on BSD) to store sessions in files, because they are properly locked. (2) Session data is stored in memory thus web server restart deletes it.



我真的很想要一个规范的描述,但任何和所有信息都值得赞赏。

最佳答案

我没有在 session 中使用共享内存,但我一直在使用 https://www.php.net/manual/en/book.shmop.php最近这似乎是用于 session 的内容。

共享内存的美妙之处在于它是一种在进程之间共享数据的疯狂快速方式。这样做的代价是,由于您只是直接存储在内存中,因此无法控制谁在何时写入(并且它不是持久的)。在内存文件系统中使用文件 session 修复了在顶部添加文件系统层的问题(REDIS 和 memcached 也处理这个问题)。

如果你在 session 中写了很多,并且有合理的机会同时运行两个请求,那么你会在某个时候得到意想不到的数据。
无论是什么问题,都与您需要依赖 session 数据的程度有关。

如果您只写一次,然后全部读取,例如在登录时存储用户 ID,那么它应该工作得很好。

关于 GC, session 模块之间应该没有区别。

关于php - 什么是 PHP 共享内存(mm,--with-mm) session 模块?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18337159/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com