在所有PHP进程之间共享变量/内存 [英] Share variables/memory between all PHP processes

查看:133
本文介绍了在所有PHP进程之间共享变量/内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在所有PHP进程之间共享变量和数组,而无需复制它们??

Is it possible to share variables and arrays between all PHP processes without duplicating them?

使用memcached,我认为PHP复制了使用的内存:
$array = $memcache->get('array');
$ array将包含memcached的副本.

Using memcached, I think PHP duplicates the used memory:
$array = $memcache->get('array');
$array will contain a copy from memcached.

所以我的想法是,可能已经定义了一个 static 变量,并在所有进程之间共享.

So my idea is, there could be a static variable that was already defined, and shared between all processes.

推荐答案

默认情况下完全不可能.每个解决方案都将始终将内容复制到当前作用域中,因为如果没有,则无法访问它.

By default its simply not possible. Every solution will always copy the content into the current scope, because if not, there is no way to access it.

我不知道自己到底想做什么,但是也许您可以在外部"进行操作,例如作为 gearman 作业,然后仅捕获该过程的结果,而不是整个数组.

I dont know, what exactly want to do, but maybe you can do that "outside", for example as a gearman job, and then just catch the results of the process, instead of the whole array.

您还可以考虑将大"数组拆分为多个切片,然后始终从apc或memcached中检索当前需要的部分.

You can also think about splitting the "big" array into slices and then always retrieve the part you currently need from an apc or memcached.

这篇关于在所有PHP进程之间共享变量/内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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