PHP-在所有PHP线程中访问全局变量
我正在为我的PHP应用程序使用pthreads.
I am using pthreads for my PHP application.
我希望我的线程读取/写入(共享)一个公共的PHP变量,即维护用户会话中所有线程的公共变量状态.
I want my threads to read/write (share) a common PHP variable, i.e. maintain the common variable state for all threads within a User Session.
我没有找到解决方法.还请提供任何脚本示例以及提出的解决方案.
I have found no solution. Please also give any script example with the solution proposed.
在大多数Web设置中,这是不可行的.这是不可行的,因为有多个进程可以处理请求.无法访问彼此内存的进程.
In most web setups, this is not feasible. It's not feasible because there are several processes serving requests; processes which cannot access each others memory.
即使有可能,这也不明智;正是这种锁定方式破坏了PHP中默认的基于文件的默认会话处理程序:您不希望所有进程都锁定一个关键部分,这是错误的设计.
Even if it were possible, it would not be sensible; this is exactly the kind of locking that cripples the default file based session handlers in PHP: You do not want all processes to lock up over one critical section, it's bad design.