Eli

To content | To menu | To search

Tag - pecl

Saturday, October 16 2010

New versions of PECL Memcache package for PHP

PECL Memcache developers have released two new versions of their package with bugs fixes and some features.

It's a very good news since this package did not have bug fixes or new features for more than one year and was declared abandonned.

PECL Memcached 2.2.6 stable releases note

  • Fixed pecl bug #16536 (Weight of 0 causes SegFault on memcache_add_server)
  • Fixed pecl bug #17130 (Uninitialized tv.tv_usec causing PHP to loop endlessly)
  • Fixed pecl bug #13623 (Memcache-client makes php segfault in semi-related code)


PECL Memcached 3.0.5 beta releases note

  • Fixed PECL bug #16059 (Build error: 'MSG_NOSIGNAL' undeclared)
  • Added method MemcachePool::findServer(key) which returns the server a key hashes to
  • Changed MemcachePool::findServer() to return only "hostname:port" since tcp port is significant
  • Fixed PECL bug #16536 (Weight of 0 causes SegFault on memcache_add_server)
  • Fixed PECL bug #17566 (3.0.4 cache delete bug)
  • Fixed PECL Bug #16442 (memcache_set fail with integer value)


You can download it now from official PECL website or using your PECL updater.

pecl upgrade memcache


Warning about 3.0.5

I strongly suggest you not to use this 3.0.5 beta
Looking at problems and huge bugs with 3.0.4, i prefer staying with 2.2.X at the moment and i suggest you to do the same.




Tuesday, August 17 2010

libMemcached 0.43 released

A new version of libmemcached the open source C/C++ client library and tools for Memcached server have been released.

Release notes :

  • Added --args to memstat so that a greater range of values can be returned.
  • Prelimanary support for Windows.
  • memcached_stat_execute() merged.

You can download it from : http://download.tangent.org/libmemcached-0.43.tar.gz




Thursday, July 8 2010

libMemcached 0.41 & 0.42 released

Two new versions of libmemcached the open source C/C++ client library and tools for Memcached server have been released.

Release notes :

  • Mistake in libtool caused issue with library version
  • Added --file for memcat
  • Added limemcached_ping() to libmemcached_util
  • Bugfix for some cases where connect would have issues with timeout
  • Wrong value for errno given as error on an IO failure inside of poll
  • Bug fix for issue where multiple interfaces with bad DNS were not being caught

You can download it from : http://download.tangent.org/




Wednesday, May 5 2010

Using cas() command from PECL Memcached

Here a simple example on how using cas() command from PECL Memcached to update data that must be at all time up to date

In Memcached, series of commands are not atomic :

A series of commands is not atomic. If you issue a 'get' against an item, operate on the data, then wish to 'set' it back into memcached, you are not guaranteed to be the only process working on that value. In parallel, you could end up overwriting a value set by something else.

But PECL Memcached come with a useful function : cas()

The principle is :

  • Make a get() to get a key value and a cas token (checksum of the value that the get return)
  • Make some update on the value
  • Ask memcached to update the value with cas() method with the cas token as parameter, to let memcached see if the actual value of the key you want to update is the same as he give before or if another script has changed it

Here the code example, we update an index array, adding values in it when not present

# Initializing Memcached connection
$memcache = new Memcached();
$memcache->addServer('localhost', 11211);
 
$indexKey = 'Our index key';
$newValue = 'Some new value to add to index';
$cas = null;
 
# Starting index updating
do 
{
  # Getting data, with parameter $cas to get as we want a cas token
  $indexData = $memcache->get($indexKey, null, $cas);
 
  # Index does not exists, initializing it
  if($indexData === false)
  {
    $indexData = array($newValue);
    $memcache->add($indexKey, $data, 1800);
  }
  # Index exists, updating it
  else
  {
    # Adding new value in index
    $indexData[] = $newValue;
    $memCache->cas($cas, $indexKey, $indexData, 1800);
  }
}
# If result is not stored, or data was updated by another thread
while(($memCache->getResultCode() == Memcached::RES_NOTSTORED) 
      || ($memCache->getResultCode() == Memcached::RES_DATA_EXISTS));

With that little script, we are sure that :

  • If no index are present at start of our script but the index is created in another thread, we retrieve it before adding our value because we use the add() command (Memcached::RES_NOTSTORED)
  • If the index is modified by another script while we are working on it, we get the up to date version before trying to add our new data, thanks to the cas() method (Memcached::RES_DATA_EXISTS)


Remember to be careful with cas(), under heavy concurrent updates, the do ... while() can easily take a lot of execution time, you must add a maximum try count break condition.

And remember to not check command success in a while loop with something like

$memCache->getResultCode() != Memcached::RES_SUCCESS

Memcached::RES_SERVER_ERROR or anything like this and your script will loop forever




Thursday, April 8 2010

libMemcached 0.39 released

Release notes :

  • Add support for prefix keys to binary protocol.
  • Remove the undocumented call memcached_server_remove().
  • The undocumented call memcached_server_by_key() now returns const.
  • memcached_server_error_reset() has been deprecated.
  • memcached_server_list() has been deprecated.
  • Use memcached_server_cursor() to walk the servers found in a memcached_st() structure.
  • memcached_verbosity() can now be run concurrently with other operations.
  • SASL support.
  • Fixes memory leak found in EJECT HOSTS.

You can download it from : http://download.tangent.org/libmemcached-0.39.tar.gz