PHP SDK : Fatal error: Class 'Couchbase' not found


#1

hello,
I am trying for the first time the php sdk, so on my local widnows 8 , 64 bit I installed WampServer for test local.
I also installed Couchbase Server Version: 3.0.3-1716 Enterprise Edition (build-1716) in the same host.
I downloaded the DLL files under http://www.couchbase.com/node/1411 ;
I placed the .DDL files php_couchbase.dll and libcouchbase.dll under C:\wamp\bin\php\php5.5.12\ext and C:\wamp\bin\apache\apache2.4.9\bin
I created a simple php to test:

<?php // adjust these parameters to match your installation $cb = new Couchbase("127.0.0.1:8091", "Administrator", "test123", "default"); $cb->set("a", 101); var_dump($cb->get("a")); ?>

I get the following error;

( ! ) Fatal error: Class ‘Couchbase’ not found in C:\wamp\www\test.php on line 3
Call Stack

Time Memory Function Location

1 0.0000 241832 {main}( ) …\test.php:0

Please help!
Thanks


#2

Hey couchbwiss,

It appears you are using the wrong sample code. Between the 1.x and 2.x SDK versions, the Couchbase class no longer exists. Take a look here for the most up-to-date information: http://docs.couchbase.com/developer/php-2.0/hello-couchbase.html.

Cheers, Brett


#3

thanks @brett19,
I still have the same issue;

Fatal error: Class ‘CouchbaseCluster’ not found in C:\wamp\www\test.php on line 4

I changed the code to the following; any idea? Thank you

<?php // Connect to Couchbase Server $cluster = new CouchbaseCluster('http://127.0.0.1:8091'); $bucket = $cluster->openBucket('beer-sample'); // Retrieve a document $result = $bucket->get('aass_brewery-juleol'); $doc = $result->value; echo $doc->name . ', ABV: ' . $doc->abv . "\n"; // Store a document $doc->comment = 'Random beer from Norway'; $result = $bucket->replace('aass_brewery-juleol', $doc); var_dump($result); ?>

#4

Hi @brett19

I just got an error from WampServer when I tried to restart it ;


#5

Hey couchbwiss,

It looks like you have downloaded the x64 version of the extension to use with a x86 PHP installation, or vica-versa. Please double-check this.

Cheers, Brett


#6

oh, … @brett19, thanks … I think I am using Php 32 bit installation and I downloaded 64 bit for my win8-64.


#7

@brett19 Hi Brett,

it has been now 5 days trying to make sdk php working and no chance
Fatal error: Class ‘CouchbaseCluster’ not found in C:\xampp\htdocs\wiss\testwiss.php on line 4

Why it is so difficult to make SDK php working for windows :frowning: (impossible in my case) ?
I donwloaded all DLL from here: https://github.com/keshavkatwe/couchbase
Installed xampp with php 5.5 32 bit on my windows 7 (64bit) , I have tried this call;

<?php // Connect to Couchbase Server $cluster = new CouchbaseCluster('http://127.0.0.1:8091'); $bucket = $cluster->openBucket('beer-sample'); // Retrieve a document $result = $bucket->get('aass_brewery-juleol'); $doc = $result->value; echo $doc->name . ', ABV: ' . $doc->abv . "\n"; // Store a document $doc->comment = 'Random beer from Norway'; $result = $bucket->replace('aass_brewery-juleol', $doc); var_dump($result); ?>

#8

Hi Couchbwiss,
I am facing same kind of problem. If you have any
solution please guide me on that.


#9

Hey @ravisharma99885,

It looks like you are starting with the Couchbase class rather than CouchbaseCluster. Please take a look at recent documentation on how to use our SDK for more information: http://developer.couchbase.com/documentation/server/4.1/sdks/php-2.0/hello-couchbase.html.

Cheers, Brett


#10

Hi Brett,

Thanks for reply

I am follow these below steps to connect couchbase server through php

Step 1: First make sure you have install wampwith php 5.5 version in windows.Because 5.6 is not supported by couchbase.

Step 2: Copy php_couchbase.dll to C:\wamp\php\ext. And copy file libcouchbase.dll to C:\wamp\php and C:\wamp\apache\bin.

Step 3: Add extension=php_couchbase.dll line to php.ini

Step 4: Restart Wamp. And it is good to go.

and i am facing this error

Fatal error: Class ‘CouchbaseCluster’ not found

and i am using WampServer


#11

I’m having a similar issue. My platform is different as I’m running Ubuntu server 14.04 with PHP 5.5.9.

The following code works fine on the command line:

	$SERVER = 'couchbase://localhost';
	$cluster = new CouchbaseCluster($SERVER);
	$bucket = $cluster->openBucket('beer-sample');

	// Retrieve a document

	$result = $bucket->get('aass_brewery-juleol');
	$doc = $result->value;

	print_r(json_decode($doc));

The file is retrieved and displayed. However, run through php-fpm, I get the following error:

PHP message: PHP Fatal error: Class 'CouchbaseCluster' not found in ... <long path and filename>

I went through phpinfo() to see if there were any Couchbase entries but there were none … but it works when I run the code through a PHP file as a shell command so I’m a bit perplexed.

What simple thing am I missing?


#12

Could you make sure you have couchbase extension loaded? Could you post output of these commands?

php -i | grep 'couchbase\|json'
php --modules | grep 'json\|couchbase'

#13

Here’s the output:

/etc/php5/cli/conf.d/20-json.ini, couchbase json json support => enabled json version => 1.3.2

I remembered that php-fpm has it’s own INI file so I added the extension in /etc/php5/fpm/php.ini as well then restarted the fpm service. Had no effect.


#14

Did you install libcouchbase from the official binary packages or build from sources?


#15

No, via binaries. Not sure I want to build from source because it’s been so long since I’ve done anything like that. IDEs like Xcode have spoiled me.

Update:
Seems that a reboot fixed my problem. Not sure why. I suspect maybe that I needed to do more than just restart php5-fpm service.


#16

On my clean box everything gone well without reboot. Just created /etc/php5/fpm/conf.d/30-couchbase.ini with

extension = couchbase.so

and then

sudo service php5-fpm restart
sudo service nginx restart

#17

I didn’t restart nginx. Didn’t think I had to but maybe I should have.


#18

These steps are not in the official documentation, right? because i did not find anything that says php 5.6 is not supported by couchbase

regardless, i am using 5.6 now because while trying to make it work with 5.5, everything got messed up so i had to reinstall and decided to install the latest version of wamp


#19

php 5.6 is supported by couchbase extension


#20

yes, you are correct. i read the changelog a few minutes ago. php 5.6 is supported since 2.0.3