Confusing documentation/ how to use persistent connections

When you look in google for pecl php couchbase you end up here :

but afaik this the old SDK and is the one that should be used?
Can’t there be a link on top of the old one to the new one to avoid confusion?

Also in the current documentation it states that for using persistent connections in couchbase you should use :

PHP: Persistent connections for PHP clients are actually persistent memory that we use across multiple requests in a PHP process. Typically you use one PHP process per system process. The web server that is currently in use in your system will determine this. To configure the PHP SDK to maintain a persistent connection you would use these parameters in your connection:

$cb = new Couchbase(“”, “default”, “”, “default”, true);

But this doesn’t work anymore with the new Couchbasecluster,
how to achieve it there?

I also find it a bit confusing on how to use the options on CouchbaseViewQuery,
need to manually look in to the code on the stub classes,
shouldn’t the group_level function also return $this?
The classes for managing views from out php were a bit trial & error to find out the right options too.

Hey Jayme,

From what I can tell, all the links on our pecl page point to our new documentation. Would you be able to identify where exactly you are seeing a link to the old documentation and repository?

P.S. The missing return $this in group_level is indeed a bug, and has been fixed.

Cheers, Brett

Thanks for the quick reply & fixes,
ah was in google that the first hit for pecl and couchbase is the old github repo.

But the current couchbasecluster is always persistent then or there is no such option anymore?

Hey Jayme,

Indeed, in all cases where it’s possible (this is dependant on your PHP installation and server environment), the SDK will maintain persistent connections to your cluster to reduce the spin-up time of your script in regards to connecting to the cluster. This difference can be astounding (difference between 100-1000ms and 0ms (depending on network topology) to create a CouchbaseBucket object).

Cheers, Brett

Hi @brett19,

Could you explain what those settings are? How can I ensure that my PHP installation is configured to use persistent connections?

Hey @moon0326,

The trick is to ensure your web server is keeping your PHP instances running for more than a single request (FCGI or SAPI module).

Cheers, Brett

1 Like

Hey brett19,

I thought about it again and I wonder how it actually works.

Even with PHP-FPM, it has to bootstrap PHP code again. When bootstrapping PHP code, it creates a new CouchbaseCluster object. How does it re-use an existing connection in this case?