APC:Alternative PHP Cache(APC)是 PHP 的一個免費公開的優化代碼緩存。它用來提供免費,公開而且強健的架構來緩存和優化 PHP 的中間代碼。
連接地址:http://php.net/manual/en/book.apc.phpphpMemcache:Memcache module provides handy procedural and object oriented interface to memcached, highly effective caching daemon, which was especially designed to decrease database load in dynamic web applications.
連接地址:http://php.net/manual/en/book.memcache.phpwebMemcached:高性能的,分佈式的內存對象緩存系統,用於在動態應用中減小數據庫負載,提高訪問速度。
連接地址:http://memcached.org/算法
APC VS Memcached數據庫
Memcached 爲分佈式緩存系統,而 APC 爲非分佈式緩存系統。api
若是你的 web 應用程序架設於不一樣的 web 服務器(負載平衡),你可使用 memcached 構建你的緩存系統。若是不是,徹底可使用 APC 來構建,並且架設於一臺服務器上,APC 的速度優於 memcached。數組
Memcached 內存使用方式也和 APC 不一樣。APC是基於共享內存和 MMAP 的,memcachd 有本身的內存分配算法和管理方式,它和共享內存沒有關係,也沒有共享內存的限制,一般狀況下,每一個 memcached 進程能夠管理2GB的內存空間,若是須要更多的空間,能夠增長進程數。 (截取自:http://blog.developers.api.sina.com.cn/?p=124)緩存
Memcached 是「分佈式」的內存對象緩存系統,那麼就是說,那些不須要「分佈」的,不須要共享的,或者乾脆規模小到只有一臺服務器的應用,memcached 不會帶來任何好處,相反還會拖慢系統效率,由於網絡鏈接一樣須要資源,即便是 UNIX 本地鏈接也同樣。 在我以前的測試數據中顯示,memcached 本地讀寫速度要比直接PHP內存數組慢幾十倍,而 APC、共享內存方式都和直接數組差很少。可見,若是隻是本地級緩存,使用 memcached 是很是不划算的。(截取自:http://blog.developers.api.sina.com.cn/?p=124)服務器
跨服務器使用 memcached,最好要使用內網,否則的話,受路由的影響,memcached 常常會鏈接超時(超過100ms),並且會憑空多出來兩倍的寬帶流量。(截取自:http://www.9enjoy.com/compare-one-server-apc-memcached/)網絡
注:更多關於Memcached信息,移步 http://blog.developers.api.sina.com.cn/?p=124架構
Memcached VS Memcache
主要區別是php memcached擴展比較新,幾乎支持 memcached 的全部特性(如 Delayed Get, Append/Prepend 等). 可是它依賴 libmemcached 才能運行(在debian裏面包名是libMemcached5).
因此若是你不使用如 Delayed Get 這樣的特性,又不想多依賴 libmemcached 庫, 徹底可使用 memcache 擴展. 反之請選擇 memcached 擴展。(截取自:http://www.leonzhang.com/2011/06/24/memcached-vs-php-memcache/)
Memcached client library was just recently released as stable. It is being used by digg ( was developed for digg by Andrei Zmievski, now no longer with digg) and implements much more of the memcached protocol than the older memcache client. The most important features that memcached has are:
All of this points were enough for me to switch to the newest client, and can tell you that it works like a charm. There is that external dependency on the libmemcached library, but have managed to install it nonetheless on Ubuntu and Mac OSX, so no problems there so far.
If you decide to update to the newer library, I suggest you update to the latest server version as well as it has some nice features as well. You will need to install libevent for it to compile, but on Ubuntu it wasn't much trouble.
I haven't seen any frameworks pick up the new memcached client thus far (although I don't keep track of them), but I presume Zend will get on board shortly.
(截取自:http://stackoverflow.com/questions/1442411/using-memcache-vs-memcached-with-php)
表格對比了這兩個擴展的具體特性
pecl/memcache | pecl/memcached | |
---|---|---|
First Release Date | 2004-06-08 | 2009-01-29 (beta) |
Actively Developed? | Yes | Yes |
External Dependency | None | libmemcached |
Features | ||
Automatic Key Fixup1 | Yes | No |
Append/Prepend | No | Yes |
Automatic Serialzation2 | Yes | Yes |
Binary Protocol | No | Optional |
CAS | No | Yes |
Compression | Yes | Yes |
Communication Timeout | Connect Only | Various Options |
Consistent Hashing | Yes | Yes |
Delayed Get | No | Yes |
Multi-Get | Yes | Yes |
Session Support | Yes | Yes |
Set/Get to a specific server | No | Yes |
Stores Numerics | Converted to Strings | Yes |
1. pecl/memcache will convert an invalid key into a valid key for you. pecl/memcached will return false when trying to set/get a key that is not valid.
2. You do not have to serialize your objects or arrays before sending them to the set commands. Both clients will do this for you.
(來源:http://code.google.com/p/memcached/wiki/PHPClientComparison)