用PHP Pecl memcache的哥们应该都知道,memcache client的add和set方法中第三个参数是表示是否用压缩存储的

bool Memcache::add ( string key, mixed var [, int flag [, int expire]] )
bool Memcache::set ( string key, mixed var [, int flag [, int expire]] )
flag
Use MEMCACHE_COMPRESSED to store the item compressed (uses zlib).

还有一个比较重要的函数,是设置要压缩阀值的

bool Memcache::setCompressThreshold ( int threshold [, float min_savings] )
threshold
Controls the minimum value length before attempting to compress automatically.

min_saving
Specifies the minimum amount of savings to actually store the value compressed. The supplied value must be between 0 and 1. Default value is 0.2 giving a minimum 20% compression savings.

其中,threshold是设置开始压缩的最小长度,大于这个长度的串才会尝