note 100972 added to memcache.add

From: Date: Thu, 18 Nov 2010 00:06:14 +0000
Subject: note 100972 added to memcache.add
Groups: php.notes 
Request: Send a blank email to php-notes+get-174139@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->add($key, $value, $compress); echo $mc->get($key); //Alternative is to cast the variable $value = is_scalar($value) ? (string)$value : $value; $mc->add($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.add.php Edit -- https://master.php.net/note/edit/100972 Del: integrated -- https://master.php.net/note/delete/100972/integrated Del: useless -- https://master.php.net/note/delete/100972/useless Del: bad code -- https://master.php.net/note/delete/100972/bad+code Del: spam -- https://master.php.net/note/delete/100972/spam Del: non-english -- https://master.php.net/note/delete/100972/non-english Del: in docs -- https://master.php.net/note/delete/100972/in+docs Del: other reasons-- https://master.php.net/note/delete/100972 Reject -- https://master.php.net/note/reject/100972 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#174139) next »