APC values randomly disappear

醉酒当歌 提交于 2019-12-02 07:14:59

It's not persistent storage. You may improve it by increasing memory size of APC but anyway, there are no warranties. So you should reinit values if you see they are dropped.

I will try to answer my own question from what I've learned.

Firstly like many people has rightly pointed out.

APC is not persistent.

It was for me hard to accept this statement without a practical explanation or even better a guide on how to work with it.

I've come to find that there are some rules or rather pitfalls to be aware of - many still eludes me. Using the APC API means using apc_fetch and apc_store both of these can fail, or as it is more correctly put, miss. And why you sometimes receive NULL when you expected data is where the mystery lies.

Here are some random bits of information:

  • If you try to store a value before the TTL runs out a new entry will be created. So slow down writing or decrease TTL.

The number of seconds a cache entry is allowed to idle in a slot in case this cache entry slot is needed by another entry. Leaving this at zero means that APC's cache could potentially fill up with stale entries while newer entries won't be cached. - http://php.net/manual/en/apc.configuration.php

  • Play around with apc.ttl and apc.user_ttl till you find something that suits you - until you see lots of hits and not to many entries.

  • apc_fetch and apc_store can return NULL for a number of reasons, some hinted above, such as ttl another reason can be a key fetch timeout. But the point is design-around it. Expect this.

If you like me have been feeling very frustated about APC's behaviour have a look at this article pointed out to me by scoates: http://phpadvent.org/2010/share-and-enjoy-by-gopal-vijayaraghavan . It will not give you much answers but some basic knowledge about cache design and perhaps like me some relief in the fact I'm not alone :)

In my case with the class-path issue described in my question, I decided to use a local variable to build up the cache and then at the end storing it in the cache with one single apc_store invocation. This brought the hits way up and the cache entries per key way down - and my code is now running fast.

APC IS persistent but separate for each apache process.

PHP mentains a separate APC CACHE storage for each apache process, which is perfectly normal because each apache process has his own memory space.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!