PHP Memcached客户端 - 压缩在设置数据时不起作用

时间:2012-10-18 11:26:12

标签: php memcached

我正在尝试php memcached客户端。对于php memcached中的set操作,默认情况下似乎是压缩。我尝试设置一个中等大小的字符串数据,当我在telnet中运行get命令时,我得到的值只是纯文本。现在,当使用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

请帮忙。

2 个答案:

答案 0 :(得分:3)

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

memcached.compression_threshold = 100

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

答案 1 :(得分:2)

您的memcached.ini供参考

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"