国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > PHP > 正文

php memcache和php memcached比較以及問題

2024-05-04 21:49:45
字體:
來源:轉載
供稿:網友

php memcache和php memcached是php的memcache分布式的高速緩存系統的兩個客戶端,php memcache是老客戶端,php memcached是功能更加完善的新的代替php memcached的.

php memcache獨立用php實現,是老客戶端,從我們實踐中已發現有多個問題,而且功能少,屬性也可設置的少;

php memcached是基于原生的c的libmemcached的擴展,更加完善,建議替換為php memcached.

1.Php memcache的問題

1.1 分布式問題

php memcache默認會自動切換實例,所以有時取到老數據,并且value飄忽不定.

網友分享的問題:

這幾天做某個產品的時候遇到一個小問題,現象比較詭異,產品用了兩臺分布式的memcached服務器,某一個計數器取回來的數偶爾會不對,最后定位在php memcache client的failover機制上面.

我們知道,在memcached分布式環境下,某一個key是通過hash計算,分配到某一個memcached上面的.

如果php.ini里面 memcache.allow_failover = 1的時候,在分布式環境下,某一臺memcached出問題的話,會自動到其他的memcached嘗試,就會出現上面的問題,所以要設置 allow_failover = 0 那么取不到時就直接返回失敗而不會從其它mc上取,這樣以避免網絡異常或server端異常時,經常切換實例,會取到老數據.

1.2 高并發下穩定性問題

新浪微博提到的教訓:

php memcache換成php memcached,在高并發下穩定下極大提高;

另外功能更多,出錯碼更精確。

Twitter的緩存經驗

多層次Cache,減輕某些cache節點宕掉后的影響,讀寫都cache;將memcached api統一換為libmemcached(方便多語言訪問memcached,讓分布式等各種規則都一致).

1.3 1秒超時間隔沒法修改問題

php memcache客戶端有個1秒超時間隔沒法修改問題:

bool Memcache::connect(string $host [,int $port [,int $timeout ]])

第三個參數本來可設置timeout,單位秒,但無法修改.

測試了以下三種修改timeout的方法都無效:

1.3.1. 用memcache api Memcache::setServerParams不能修改;

1.3.2. 改memcache 源代碼vi php_memcache.h宏定義不能修改;

1.3.3. php.ini內這個配置:default_socket_timeout = 60對本timeout無效。

2.memcache和memcached對比

Php memcache這個老客戶端在屬性設置方面可設置的很少,出錯碼粒度很粗,出錯后難以定位,而且功能欠缺一些:

  1. There are primarily two clients used with PHP. One is the older, more widespread pecl/memcache and the other is the newer, less used, more feature rich pecl/memcached. 
  2. Both support the basics such as multiple servers, setting vaules, getting values, increment, decrement and getting stats. 
  3.  
  4. Here are some more advanced features and information. 
  5. 項目              pecl/memcache       pecl/memcached 
  6. First Release Date      2004-06-08      2009-01-29 (beta) 
  7. Actively Developed      Yes             Yes 
  8. External Dependency     None            libmemcached 
  9. Automatic Key Fixup1    Yes             No 
  10. Append/Prepend          No              Yes 
  11. Automatic Serialzation2 Yes             Yes 
  12. Binary Protocol         No              Optional 
  13. CAS                     No              Yes 
  14. Compression             Yes             Yes 
  15. Communication Timeout   Connect Only    Various Options 
  16. Consistent Hashing      Yes             Yes 
  17. Delayed Get             No              Yes 
  18. Multi-Get               Yes             Yes 
  19. Session Support         Yes             Yes 
  20. Set/Get to a specific server    No          Yes 
  21. Stores Numerics         Converted to Strings    Yes 
  22. //開源軟件:Vevb.com 
  23. //注釋: 
  24.  
  25. 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. 
  26. 2 You do not have to serialize your objects or arrays before sending them to the set commands. Both clients will do

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 洪泽县| 苏尼特左旗| 凤城市| 万全县| 含山县| 奉化市| 比如县| 于田县| 通渭县| 高安市| 兰溪市| 漠河县| 米易县| 游戏| 太保市| 延川县| 卓尼县| 大新县| 桂平市| 襄樊市| 甘泉县| 陈巴尔虎旗| 巴中市| 抚顺县| 广西| 泰安市| 盐池县| 衡山县| 宿松县| 加查县| 灵石县| 准格尔旗| 香河县| 新昌县| 辽阳县| 大埔区| 寿宁县| 黎平县| 肥东县| 保德县| 太和县|