【发布时间】:2017-05-06 06:24:39
【问题描述】:
假设我有一个网站,它在启动时写入数据库。如果多个用户同时登录该网站,是否意味着它将尝试向数据库写入 N 次,其中 N = 用户数?有没有办法强制 PHP 仅在连接断开时才写入数据库(仅在所有其他用户当前不在网站上时才写入)?您建议采用什么方法来减少对数据库的过多写入或请求的可能性?
【问题讨论】:
-
取决于服务器配置,但 PHP 的默认设置是将会话写入硬盘驱动器上的文件,而不是写入数据库。
-
Is there any way to force PHP to only write to the database if the connections are disconnected (only write if all other users are currently not on the website)?- 我几乎不怀疑。服务器将如何跟踪需要稍后插入的所有未决数据?假设有 1M 用户数据需要稍后插入。就我而言,数据插入必须是即时的。
标签: javascript php memory redis session-cookies