Fatal error: Uncaught exception 'CouchbaseServerException' with message '[0, ]' in xyz.php on line x


#1
Fatal error: Uncaught exception 'CouchbaseServerException' with message '[0, ]' in xyz.php on line x
  • Couchbase Server : Version: 2.5.1 enterprise edition (build-1083)
  • PHP SDK : version 1.2.0 (installed using sudo pecl install couchbase - Actually installs 1.2.2 but don't know why phpinfo() reports the version as 1.2.0)
  • libcouchbase version 2.4.0

Getting this error in PHP SDK.

Trying to get results of a view without any additional parameters being sent.

This happens frequently. Actually if you keep on reloading the same php page, it works.

But if I leave it for sometime, switch to another appllication, and then reload the same page, it happens again. unless you hit reload once more.

This is nerve wracking and very sad setback for something so simple and basic.

As per different forum message and replies, I have already done the following :

Changed the connection to not use the port number.
Changed the username from blank to bucketname
changes the host name to 127.0.0.1 and also localhost and tried with both.

The issue remains the same.
Leave it for sometime, and the query to the view gives the above error. Reloading the page, works, but again leave it for sometime, the issue remain same.

I also did the following thinking it could be timing out or something., the issue remains the same irrespective of any of these settings.

ini_set(‘couchbase.view_timeout’, 2000);
ini_set(‘couchbase.skip_config_errors_on_connect’, true);

Any insights on what could be causing this and whether the PHP SDK can be used at all for any real production work ?

Starting on a project and decided to give couchbase a try, so any quick reply will be helpful


#2

I am also receiving this error, it doesn’t occur consistently as sometimes the view is working fine without any issues. Below is a dump of the exception. You can see that the exception doesn’t include the second part of the startkey. Why would this be occurring randomly?

Couchbase Server Exception:
Uncaught exception ‘CouchbaseServerException’ with message ‘[0, ]’

This is the startkey:

array (
0 => ‘b92d37b0-1e9b-11e4-8c21-0800200c9a66’,
1 =>
array (
0 => 2014,
1 => 8,
2 => 8,
3 => 1,
4 => 27,
5 => 32,
),

This is the endkey:

) array (
0 => ‘b92d37b0-1e9b-11e4-8c21-0800200c9a66’,
1 =>
array (
0 => 2014,
1 => 8,
2 => 8,
3 => 1,
4 => 28,
5 => 40,
),

Exception dump:

) CouchbaseServerException::__set_state(array(
‘message’ => ‘[0, ]’,
‘string’ => ‘’,
‘code’ => 0,
‘file’ => ‘/usr/share/nginx/html/test.php’,
‘line’ => 525,
‘trace’ =>
array (
0 =>
array (
‘file’ => ‘/usr/share/nginx/html/test.php’,
‘line’ => 525,
‘function’ => ‘view’,
‘class’ => ‘Couchbase’,
‘type’ => ‘->’,
‘args’ =>
array (
0 => ‘people’,
1 => ‘available’,
2 =>
array (
‘startkey’ =>
array (
0 => ‘b92d37b0-1e9b-11e4-8c21-0800200c9a66’,
1 =>
a in /usr/share/nginx/html/test.php on line 527


#3

Here is one real real NASTY little trick that will work.

Just get/query a known KEY – $couchbase->get(‘my_know_key_that_exists’) before calling the view.
You would probably wrap that in the exception handling of the call to the view and do a second call again to the view. That will at least ensure not to send repeated gets on each and every query to a view.

Hope that helps.

It seems, no one from the couchbase team really bothers to answer such critical queries, specially when they know it is the community that actually tests their work in adverse conditions. I really do not see much of open-sourceness here, and it gives me a feeling as if there is encouragement to always get a paid subscription for support to cater to even to such basic errors/issues.

This is indeed very disturbing. Look at the number of questions which are critical for starters and they are still unanswered.

is anyone in the couchbase listening or reading this ?


#4

If you got my workaround working, please share and confirm so that other people can benefit.


#5

I agree with your comments regarding the open-sourceness here. I have sent an email through to Couchbase staff and asked them to look into this issue.

I also disagree with how Couchbase is holding back the community releases so they are always one major release behind. The community should be able to use the latest release without having to pay over $8000 to run three Couchbase servers for high-availability/failover functionality. It is fine to include hot fixes in the paid channels and offer enhanced support, however I don’t agree with withholding a major update until they have the next version ready.

I will try hard coding a $couchbase->get() in the catch block to see if this helps with the issue. If this fails then I might need to consider migrating to something else.


#6

It looks like calling a $couchbase->get() in the catch block when this exception occurs and then recalling the view may in fact fix this issue. I would like to test this for a few more days before being 100% certain though.

Still waiting on an official update from Couchbase staff on this issue.


#7

Could you share following:

  • View function that you’re querying against,
  • Code snippet where you’re leveraging Couchbase PHP SDK and seeing CouchbaseServerException, and
  • Steps to replicate this issue.

#8

@asingh Below are some more details regarding this issue.

function (doc, meta) {
if (doc.meta && doc.meta.type == ‘person’) {
if (doc.datetime) {
emit([doc.meta.account, dateToArray(doc.datetime)], null);
} else {
emit([doc.meta.account, dateToArray(doc.updated)], null);
}
}
}

PHP code is something like:

try {
$result = $couchbase->view(‘people’, ‘available’, array(
‘startkey’ => $startkey,
‘endkey’ => $endkey
));
} catch (CouchbaseServerException $e) {
// Dump Error
// if I run a $couchbase->get() then
// another try/catch block for the view the issue will fix itself
}

I have dumped the $startkey and $endkey variables and nothing is wrong with them, the account and date is passed in as an array.

I don’t really have any steps to reproduce the issue, sometimes the view will work and sometimes it won’t. There is nothing wrong with the key data I am passing in, so I am not sure why Couchbase says the second element of the key is empty (i.e. Uncaught exception ‘CouchbaseServerException’ with message ‘[0, ]’). Like @acpadhi said in the comments, if you catch the error and then run a $couchbase->get() then reissue the $couchbase->view() the issue won’t occur again. Running couchbase 2.2 Community on this, so I don’t know if the bug has been fixed in Couchbase 2.5 etc.

Any ideas. The workaround isn’t really suitable for a production system.


#9

I tried to replicate this issue, but wasn’t able to:

  • Populated 1M items in the “default” bucket using “/opt/couchbase/bin/cbworkloadgen -i 1000000 -j”

  • Created a basic view:
    “function (doc, meta) {
    emit(meta.id, null);
    }”

  • Used a simple PHP program:

"<?php
$cb = new Couchbase(“127.0.0.1:8091”, “”, “”, “default”);

    $result = $cb->view("ddoc", "view", array("startkey" => "pymc0", "endkey" => "pymc3"));
    foreach($result["rows"] as $row) {
            echo $row['key'] . "\n";
    }

?>"

and got expected results:

$ php sample.php | wc -l
222224


If you have a reproducible test case, it will help.


#10

@asingh Can you try replicate this with a composite key, which is handling a date like I have provided in my sample? Your example isn’t dealing with dates, nor an array is the startkey / endkey.


#11

@asingh Can you try replicate this with a composite key, which is handling a date like I have provided in my sample? Your example isn’t dealing with dates, nor an array is the startkey / endkey.


#12

I have the same issue.
The weird thing is that i do not have this issue on the cli. But only when run "on the browser"
Maybe it has something to do with nginx or php-fpm?


#13

Hey Jordy,

You should try the latest version of the PHP SDK (2.0.2) which was released today. It fixed some known issues related to the SDK behaving oddly when running on a web server as opposed to the CLI.

Cheers, Brett


#14

I have also seen this problem popping up randomly since foerever. I just came by to check if there is a solution for it but it seems there is not. At the time I’m posting this I’m using Couchbase Server 3.0.1, libcouchbase 2.4.3 and php-pecl-couchbase-1.2.2 . Same results as always: Randomly the view craps out with the following message:

PHP Fatal error:  Uncaught exception 'CouchbaseServerException' with message '[0, ]' 

I’d love to try the PHP SDK version 2, but unfortunately we have quite a lot of code running on version 1, so that is not an option for us.


#15

Thanks for the tip @acpadhi , I can confirm that querying an existing doc before calling the view seems to make the exception dissapear. An ugly hack but makes it work.