PHP-在所有PHP线程中访问全局变量 [英] PHP - Accessing a global variable across all php threads

查看:150
本文介绍了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.

这篇关于PHP-在所有PHP线程中访问全局变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆