Affects Version/s: 1.0.4
Fix Version/s: 1.1.0
Security Level: Public
Environment:With both php-ext-couchbase-1.0.5-centos55-x86_64.tar.gz and php-ext-couchbase-1.0.6b23_centos-5.5-x64.tar.gz. I will attach php -i output as a separate comment. Using php-pecl-memcached extension 1.0.0. libmemcached 1.0.4.
The existing memcached clients for PHP (pecl-memcached and memcache) both default to using fastlz compression for values >= 2000 bytes.
The couchbase client library doesn't have fastlz compression included. It doesn't provide a useful error message when it runs into this problem. Instead, it misinterprets the stored value, tries to allocate a huge block of memory and fails. The error it gives (look, e.g., in the PHP-FPM web-access.log) is:
[01-Nov-2012 20:45:49 UTC] PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 8460104323416721361 bytes) in /usr/share/nginx/html/cb.php on line 32
To reproduce, just set a value >= 2000 bytes with pecl-memcached client, and try to read it with Couchbase client. Here's a sample:
<title>Couchbase Server PHP Test</title>
$host = "10.4.2.15";
$user = "Administrator";
$password = "password";
$bucketName = "default";
$persistConnection = false;
$cb = new Couchbase($host . ":8091",
$user, $password, $bucketName, $persistConnection);
$mc = new Memcached('Pool-1');
if (count($mc->getServerList()) == 0)
// Change this to 1999 and it will work
$valLength = 2000;
$val = date(DateTime::RFC2822) . ' ';
$val .= str_repeat('X', $valLength - strlen($val));
echo("The value for 'a' is: ");
The correct behavior is for the Couchbase client to ship, out of the box, compatible with existing Memcached client implementations. It should include fastlz support directly, or else clearly document how to add such support without requiring any unusual compilations or other hoops. The fastlz code is very small and portable, and hasn't changed since 2007, so it should present a minimal maintenance issue.
In addition, the PHP client documentation should clearly indicate what changes are needed in order for the client to be compatible with the other Couchbase clients (Java, .NET, etc.). Again, without requiring recompilation or extra hoops to jump through.