Search code examples
phpshared-memory

Share variables/memory between all PHP processes


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

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

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


Solution

  • 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.

    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.

    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.