使用php apc模块需要注意的几点
在maillist中看到Rasmus的一段对于php APC模块的发言。作为APC的作者,他的见解应该是很有参考价值的。
APC will probably be 20-30% faster, but if you are writing to it frequently it can cause problems. The APC cache is best for things that change very rarely. And by very rarely I mean days, not hours or minutes.
Because of the way APC does an anonymous file-backed mmap where I unlink the file at startup to get process-death protection, it isn’t easy to get at the cache from a separate standalone command line script. That can be solved by mmap’ing slightly differently, but in the default config your approach won’t work.
-Rasmus
就是说APC不适合用于频繁写的场合,你最好只用它来保存那种几天都不会更改的内容。否则出了莫名其妙的问题就不好怎么解释了。
在以前的应用中,我确实有将apc用在频繁写的场合,偶尔会出现内存耗尽,进而引起所有http请求卡死,形式一发不可收拾整个服务器当掉。所以现在我仅仅用apc来缓存opcode的php代码,不在程序中显式的调用它,算是相安无事。
APC是什么
Alternative PHP Cache (APC)是一种对PHP有效的开放源高速缓冲储存器工具,它能够缓存opcode的php中间码。
作者: Volcano 发表于May 23, 2007 at 8:18 am
ykzj 于 2010-04-26 @ 19:51:22 留言 :
APC的写入效率比memcache要慢很多,我也用来进行opcode的缓存,希望apc作者能在以后将这个功能完善,并且加入多台服务器之间内存的同步机制,这样可以方便scale-out的扩展
Volcano 于 2010-04-27 @ 04:39:19 留言 :
在单机上apc写入比memcache快一倍,不是慢很多。
另外两者使用场景不一样,apc就是针对单机,而memcache适合通过网络连接,所以apc不会加入多服务器之间同步机制。