PHP Client Library
Couchbase and PHP
Note: Version 1.1 is the most recent release of this SDK. It is recommended for all deployments.
The easiest way to get started with Couchbases and is our PHP SDK For Couchbase Server 1.8.
Download and Installation
See the right sidebar for your download options. Note that a prerequisite for installation of this client library is the C client library.
After download, unpack the archive:
The resulting directory includes a file called couchbase.so that is the PHP extension for your system.
Edit your php.ini to include this line:
If you are unsure where to find the PHP in your configuration path, find it by running php -i | grep php.ini or look at your <?php phpinfo() ?> output.
Note: With the PHP packages on many Red Hat/CentOS distributions (and possibly others), PHP's JSON encoding is not available to other extensions by default. As a result, you may see an error resolving the php_json_encode symbol. The solution is to edit ini file that loads the JSON extension (typically /etc/php.d/json.ini) to add the Couchbase extension after the JSON extension.
Create this PHP script. It gets you started in three little steps:
$cb = new Couchbase("127.0.0.1:8091"); // uses the default bucket
// or specify a specific bucket like so:
//$cb = new Couchbase("127.0.0.1:8091", "bucket", "pass", "bucket");
The line with new Couchbase() establishes a connection to our Couchbase Server installation and gives us access to the Couchbase Server API. Next, we set the value of the key "a" to 1. Finally, we get the value for our key "a" and print it out. When you run this script, it should print int(1).
For more information, please see the Getting Started Guide.
If you have any questions, problems or suggestions, please let us know on the Couchbase SDK forums.