开发者

php super super globals

I was wondering, I have this big array, is it possible to have it only once in memory ra开发者_StackOverflowther 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?


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


For this you can use the shmop functions or a dedicated memory cache like memcached.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜