php在不同的用户/会话之间共享变量

问题描述:

我想为访问系统的所有不同用户/客户端提供一个具有相同值的变量.

i want to have a variable that has the same value for all the different users/clients accessing the system.

变量的值也必须是可修改的.

also the variable's value has to be modifiable.

就像任何一个用户更改了值一样,更改也必须反映给所有其他用户.

like if any one user changes the value, the change has to get reflected to all other users too.

将变量存储在共享空间中,例如

Store the variable in a shared space like

  • 一个文件

  • A file

数据库记录(最容易实现锁定,请参见下文)

A database record (easiest for implementing locking, see below)

内存缓存存储区

您可以在此处轻松地对其进行修改.当多个用户尝试编辑比赛条件时,您可能需要使用某种锁定机制同时值.

you can easily modify it there. You may need to use some sort of locking mechanism to prevent race conditions when multiple users try to edit the value at the same time.