3

我正在尝试使用 php memcached 客户端。似乎默认情况下,对于 php memcached 中的设置操作,压缩是打开的。我尝试设置一个中等大小的字符串数据,当我get在 telnet 中运行命令时,我得到的值只是纯文本。现在,当使用 memcache 完成相同操作时,该值会出现乱码/难以辨认。这不仅是我在 telnet 中检查了统计信息。这是结果

memcache - compressed
bytes - 148
memcache - uncompressed
bytes - 285

memcached - uncompressed
bytes - 285
memcached - uncompressed
bytes - 285

如您所见,使用 php memcache 压缩了 50%。所以压缩确实有效。但是使用 php memcached 我没有压缩。即使我使用以下命令显式打开压缩也是如此:

$objMemcached->setOption(Memcached::OPT_COMPRESSION, true);  //default fastlz compression
OR
$objMemcached->setOption(Memcached::OPT_COMPRESSION, true);
$objMemcached->setOption(Memcached::OPT_COMPRESSION_TYPE, Memcached::COMPRESSION_ZLIB );

我是否需要设置任何其他选项才能使其正常工作?自从 3 周以来我一直从事这个项目,如果压缩不起作用,我的老板不会接受从 memcache 到 memcached 的迁移。我希望你理解紧迫性;)(kiddnig)。

版本:

memcached     - 1.4.5
php-memcached - 2.0.1
libmemcached  - 1.0.8

请帮忙。

4

2 回答 2

3

尝试在 php.ini 中设置 memcached.compression_threshold

memcached.compression_threshold = 100

然后设置值并使用 telnet 进行检查。

于 2012-10-19T12:10:04.847 回答
2

您的 memcached.ini 供参考

内存缓存文件

; Enable PECL memcached extension module

extension = memcached.so

; Use memcached as a session handler
; valid values: files, memcached
; the default value is memcached

;session.save_handler = "memcached"

; Comma separated list of servers to use for session storage
;session.save_path = "127.0.0.1:11211"

[memcached]
; Use session locking
; valid values: On, Off
; the default value is On

memcached.sess_locking = On

; Session spin lock retry wait time in microseconds
; Be carefull when setting this value.
; valid values: integers, where 0 is interpreted as default
; Negative values result in a reduced locking to a try lock.
; the default value is 150000

memcached.sess_lock_wait = 150000

; Session key prefix
; valid values: strings less than 219 bytes long
; the default value is "memc.sess.key."

memcached.sess_prefix = "memc.sess.key."

; Session binary mode

memcached.sess_binary = Off

; Compression type
; valid values: fastlz, zlib
; the default value is fastlz

memcached.compression_type = "fastlz"

; Compression factor
; Store compressed value only if the compression
; factor (saving) exceeds the set limit.
; Store compressed if:
; plain_len > comp_len * factor
; the default value is 1.3 (23% space saving)

memcached.compression_factor = "1.3"

; Compression threshold
; Do not compress serialized values below this threshold.
; the default value is 2000 bytes

memcached.compression_threshold = 100

; Default serializer for new memcached objects
; valid values: php, igbinary, json, json_array
; json - standard php JSON encoding. This serializer
; is fast and compact but only works on UTF-8
; encoded data and does not fully implement
; serializing. See the JSON extension.
; json_array - as json, but decodes into arrays
; php - the standard php serializer
; igbinary - a binary serializer
; the default value is igbinary

;memcached.serializer = "igbinary"
于 2012-10-19T12:46:12.537 回答