note 100971 added to memcache.set

From: Date: Thu, 18 Nov 2010 00:04:21 +0000
Subject: note 100971 added to memcache.set
Groups: php.notes 
Request: Send a blank email to php-notes+get-174138@lists.php.net to get a copy of this message
If you're interested in using compression, please note that, at least for PHP version 5.3.2 and Memcache version 3.0.4, when retrieving a key who's value is a numeric or boolean type, PHP throws a notice of the following: Message: MemcachePool::get(): Failed to uncompress data The way around this is to test your variable type before setting or adding it to Memcache, or even cast it as a string. <?php $key = 'mc_key'; $value = 12345; $compress = is_bool($value) || is_int($value) || is_float($value) ? false : MEMCACHE_COMPRESSED; $mc= new Memcache; $mc->connect('localhost', 11211); $mc->set($key, $value, $compress); echo $mc->get($key); //Alternative is to cast the variable $value = is_scalar($value) ? (string)$value : $value; $mc->set($key, $value, MEMCACHE_COMPRESSED); ?> ---- Server IP: 69.147.83.197 Probable Submitter: 67.108.10.115 ---- Manual Page -- http://www.php.net/manual/en/memcache.set.php Edit -- https://master.php.net/note/edit/100971 Del: integrated -- https://master.php.net/note/delete/100971/integrated Del: useless -- https://master.php.net/note/delete/100971/useless Del: bad code -- https://master.php.net/note/delete/100971/bad+code Del: spam -- https://master.php.net/note/delete/100971/spam Del: non-english -- https://master.php.net/note/delete/100971/non-english Del: in docs -- https://master.php.net/note/delete/100971/in+docs Del: other reasons-- https://master.php.net/note/delete/100971 Reject -- https://master.php.net/note/reject/100971 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#174138) next »