Reputation: 3518
I was wondering, I have this big array, is it possible to have it only once in memory rather then once per thread? Take the tags here at stackoverflow as example. They barely ever change, why not have a single memory spot for them? And maybe even keep that array permanently in memory?
Upvotes: 5
Views: 330
Reputation: 7956
each php process runs isolated from others. This is different from java for example where when you have a single object you can make live until the JVM is restarted.
sadly if you have an object (small or big) it will be loaded each time the php script runs BUT if you want to share something in memory between runs you could use APC, memcache or shared memory
Between those options I highly recommend you APC.
Upvotes: 1
Reputation: 522210
For this you can use the shmop
functions or a dedicated memory cache like memcached.
Upvotes: 2
Reputation:
No -- the synchronization issues inherent in sharing a single variable directly between PHP interpreters make that impossible. It's much more likely that Stack Overflow simply avoids "thinking about" the whole tags array at once.
You can use the variable storage functions in APC (apc_store and apc_fetch) to store serialized data in shared memory, though.
Upvotes: 0
Reputation: 14705
Take a look at apc_store
Unlike many other mechanisms in PHP, variables stored using apc_store() will persist between requests (until the value is removed from the cache).
Upvotes: 4