Fatal error: Class 'Couchbase' not found


I’m very new to Couchbase. Previously tried using the C SDK. I managed to figure out how to use it.
But now I’m trying to get it to work with PHP so that I can set up some web service to provide a read and write access to couchbase.

However, I can’t even get past the initial stages of running some sample codes.


define("COUCHBASE_CONNSTR", "");
define("COUCHBASE_BUCKET", "SaveData");
define("COUCHBASE_PASSWORD", "password");
define("COUCHBASE_VIEW", "player");
define("DOCUMENT_KEY", "10001_RP");
define("INDEX_DISPLAY_LIMIT", 10);

if (extension_loaded('couchbase'))
    //connecting to the cluster
    $cluster = new CouchbaseCluster(COUCHBASE_CONNSTR);

    //opening the bucket
    $bucket = $cluster->openBucket(COUCHBASE_BUCKET, COUCHBASE_PASSWORD);

    $result = $bucket->get(DOCUMENT_KEY);
    if ($result == true)
        $doc = $result->value;
        if ($doc)
            $changed = json_decode($doc, true);       
            $changedObj = $changed["name"];
            echo 'Details:'.$changedObj."\n"; 
            $result = $bucket->replace(DOCUMENT_KEY, $doc);
    $query = CouchbaseViewQuery::from(COUCHBASE_BUCKET, COUCHBASE_VIEW)->limit(INDEX_DISPLAY_LIMIT);


Up to the part where I try to do a GET with the document key, there’s no problems.
but when I try to run a replace, it says “Fatal error: Call to undefined method CouchbaseBucket::replace()”

when I try to use Couchbase to create a new connection and access it via a view, i get
"Fatal error: Class ‘Couchbase’ not found"

When I try to use CouchbaseViewQuery, it also gives me the same problem.

I’m not sure where I went wrong. but it pretty much looks like a pathing issue or I’m not including something somewhere.

This is how I set up my environment.

  1. Install XAMPP on my machine (32bit version). My windows is 64 bits though.
  2. Download the precompiled Libraries (php_couchbase-2.0.0-5.5-zts-vc11-x86.zip) (32bit version)
  3. Download the precompiled Libraries for couchbase C SDK. (libcouchbase-2.4.3_x86_vc11.zip) (32bit version)
  4. Copied all the required DLL files to the locations they need to be at (I basically followed the instructions here (http://trondn.blogspot.no/2013/04/couchbase-php-xampp-and-windows.html)
  5. Start up my Apache Server
  6. Check phpinfo()

I see this
Version 2.0

  1. and I started testing my php scripts using php.exe.

and I’m stuck.

Please advise… I’m completely lost…

oh please do ignore the logic in the code. I"m just randomly running the commands to make sure it all works before I start developing proper.

Hey danielphua,

Please ensure you are using the latest version of the PHP SDK, there are a couple of known issues with the original release that could cause what you are seeing. Additionally, keep in mind that the Couchbase class is from the 1.x series of SDKs, whereas the CouchbaseCluster and CouchbaseBucket classes are the new ones from the 2.x series.

Cheers, Brett

Hello brett,

Thanks for the reply.
I’m pretty sure I was using the latest PHP SDK. I think I pasted the wrong file name on my post.

I downloaded the dll file from http://sdk-snapshots.couchbase.com/php/php_couchbase-2.0.1-5.5-zts-vc11-x86.zip

My couchbase C SDK is one small versison older though. it was 2.4.3. I see that it is now 2.4.4. But I think this is more of a PHP end issue.

But I’ll go give it a shot again and see if I really used the wrong version of the SDK.

However, are my setup steps correct? is there any additional steps I should have taken but didn’t?

Oh and the Couchbase class you see in my code is just some code I took reference from . It was probably an outdated document.

However, what is odd here is that
bucket->replace(…) doesn’t work for me. It gives me the same error that the class cannot be found.
bucket->insert(…) works when I gave it a try just a while back.

would compiling my own php_couchbase.dll help?

I tried downloading the latest of both C and PHP libraries. The problem still exists.

Update again
I did a get_class_methods


This was what I got. Interestingly, there’s no “query” in the methods. And the methods here don’t match the API References at http://docs.couchbase.com/sdk-api/couchbase-php-client-2.0.1/classes/CouchbaseBucket.html which is really odd

array(5) {
  string(11) "__construct"
  string(10) "openBucket"
  string(11) "openQuerier"
  string(7) "connect"
  string(4) "info"
array(16) {
  string(11) "__construct"
  string(6) "insert"
  string(6) "upsert"
  string(4) "save"
  string(6) "remove"
  string(3) "get"
  string(7) "counter"
  string(6) "unlock"
  string(4) "find"
  string(4) "view"
  string(5) "flush"
  string(4) "info"
  string(6) "endure"
  string(13) "setTranscoder"
  string(5) "__get"
  string(5) "__set"

and I also managed to make CouchbaseViewQuery declared by including these files from the source codes. But I don’t think that’s the way to do it though =(


Anyone? I’m resorting to using the couchbase REST API for now to get the views. But I’m pretty sure I can’t use that as a solution.

Hey danielphua,

You should be using the CouchbaseCluster class in concert with the CouchbaseBucket class which is retrieved by the openBucket method of CouchbaseCluster. Check out the developer documentation for further information!

Cheers, Brett

Hi Brett,

Yes, I’m already using CouchbaseCluster and CouchbaseBucket together.

$server = json_decode(file_get_contents("server.json")); 
$host = $server->couchbase->host; 
$bucket = $server->couchbase->bucket;
$password = $server->couchbase->password;

$cluster = new CouchbaseCluster($host);

$bucket = $cluster->openBucket($bucket, $password);

$query = CouchbaseViewQuery::from($bucket , "by_player")->limit(10);

“$query = CouchbaseViewQuery::from($bucket , “by_player”)->limit(10);” <— it will say CouchbaseViewQuery not found.

In fact, I’m also getting another problem with memory.

Just to update.

I’ve managed to compile by own php_couchbase.dll.

And the missing classes in the dll is resolved.

However, memory allocation issues and invalid callback errors still occur.

"Fatal error: Possible integer overflow in memory allocation (1073741824 * 4 + 0) in CouchbaseNative on line 1184"
“Warning: Invalid callback , no array or string given in CouchbaseNative on line 1184”

and also, making a call to GET seems to take very long randomly. Sometimes it’s really fast. sometimes it just stalls for so long that it times out.

This is what I simply did
$result = $bucket->get($playerKey);

of course before this code is the creating of couchbaseCluster and openning of the bucket
$cluster = new CouchbaseCluster($host);
$bucket = $cluster->openBucket($bucket, $password);
These codes didn’t cause any stalling.

New version released! I have a few confirmations that it fixes the known issues you were encountering.
Read more here: http://docs.couchbase.com/developer/php-2.0/release-notes.html

Cheers, Brett

hey brett,

thanks. but there’s something strange about the pre-built binary files.

when I download the files and unzip them, the php_couchbase.dll file is dated 24/06/2014. Is that normal?

the 2 package.xml files are up to date at 02/12/2014.

Hey danielphua,

This is indeed strange, I will take a look. I suspect its simply a date sync problem on the build bots.

Cheers, Brett

Hi Brett,

Yes its really strange. I’ve downloaded all 3 version of the dll. 2.0.0, 2.0.1 and 2.0.2

All of them give me the same modified Data and all have the same CRC32 value too.

Which is really really weird… unless all of the compiled dll files are the same…

Hey danielphua,

I’ll be taking a look into this. I have opened a ticket to track this issue here: https://www.couchbase.com/issues/browse/PCBC-313.

Cheers, Brett