国产精品天干天干,亚洲毛片在线,日韩gay小鲜肉啪啪18禁,女同Gay自慰喷水

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

phpmemcache與phpmemcached以及遇到的問題

2023-08-28 09:12 作者:左音king  | 我要投稿

PHP有兩個memcache客戶端:php memcache和php memcached。

php memcache獨立用php實現(xiàn),是老客戶端,從我們實踐中

已發(fā)現(xiàn)有多個問題,而且功能少,屬性也可設(shè)置的少;

php memcached是基于原生的c的libmemcached的擴展,

更加完善,建議替換為php memcached。


1. Php memcache的問題

1.1 分布式問題

php memcache默認(rèn)會自動切換實例,所以有時取到老數(shù)據(jù),并且value飄忽不定。

網(wǎng)友分享的問題:

這幾天做某個產(chǎn)品的時候遇到一個小問題,現(xiàn)象比較詭異,

產(chǎn)品用了兩臺分布式的memcached服務(wù)器。某一個計數(shù)器取回來的數(shù)偶爾會不對,

最后定位在php memcache client的failover機制上面。

我們知道,在memcached分布式環(huán)境下,某一個key是通過hash計算,

分配到某一個memcached上面的。

如果php.ini里面 memcache.allow_failover = 1的時候,在分布式環(huán)境下,

某一臺memcached出問題的話,會自動到其他的memcached嘗試,

就會出現(xiàn)上面的問題。所以要設(shè)置 allow_failover = 0 那么取不到時

就直接返回失敗而不會從其它mc上取,這樣以避免網(wǎng)絡(luò)異?;?/p>

server端異常時,經(jīng)常切換實例,會取到老數(shù)據(jù)。


1.2 高并發(fā)下穩(wěn)定性問題

新浪微博提到的教訓(xùn):

php memcache換成php memcached,在高并發(fā)下穩(wěn)定下極大提高;

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


Twitter的緩存經(jīng)驗

多層次Cache,減輕某些cache節(jié)點宕掉后的影響,讀寫都cache;

將memcached api統(tǒng)一換為libmemcached(方便多語言訪問

memcached,讓分布式等各種規(guī)則都一致。)


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

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

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

第三個參數(shù)本來可設(shè)置timeout,單位秒,但無法修改。

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

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

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

1.3.3. php.ini內(nèi)這個配置:default_socket_timeout = 60對本timeout無效。


2. memcache和memcached對比

Php memcache這個老客戶端在屬性設(shè)置方面可設(shè)置的很少;

出錯碼粒度很粗,出錯后難以定位;

而且功能欠缺一些:

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.

Both support the basics such as multiple servers, setting vaules,?

getting values, increment, decrement and getting stats.


Here are some more advanced features and information.


1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

項目 pecl/memcache pecl/memcached

First Release Date 2004-06-08 2009-01-29 (beta)

Actively Developed Yes Yes

External Dependency None libmemcached

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

本文來源:https://www.fushouyu.com/shouyou/214.html

phpmemcache與phpmemcached以及遇到的問題的評論 (共 條)

分享到微博請遵守國家法律
眉山市| 丰台区| 县级市| 光山县| 山东省| 渝中区| 方正县| 怀仁县| 积石山| 称多县| 鄂温| 芒康县| 綦江县| 秭归县| 庄河市| 佛教| 永川市| 聊城市| 抚松县| 临江市| 嘉禾县| 伊宁市| 杨浦区| 博爱县| 平昌县| 克东县| 金山区| 蚌埠市| 远安县| 平遥县| 象州县| 勃利县| 饶平县| 江源县| 溧水县| 库尔勒市| 武乡县| 司法| 乐昌市| 洱源县| 郓城县|