Giter VIP home page Giter VIP logo

php-couchbase's Introduction

Couchbase PHP Client

This library allows you to connect to a Couchbase cluster from PHP. It is a native PHP extension and uses the very fast libcouchbase library to handle communicating to the cluster over the Couchbase binary protocol.

Build Status

Useful Links

Source - http://github.com/couchbaselabs/php-couchbase

Bug Tracker - http://www.couchbase.com/issues/browse/PCBC

Couchbase PHP Community - http://couchbase.com/communities/php

Installing

This iteration of the Couchbase PHP client is not currently available via PECL, and as such must be compiled manually in order to be used. The extension will become available via PECL once it leaves the DP phase. Until then, you may install by downloading a prebuilt binary of the DP available on couchbase.com for the Windows platform, or by checking out the repository and building it directly:

phpize
./configure --enable-couchbase
make && make install

Introduction

Connecting to a Couchbase bucket is as simple as creating a new Connection instance. Once you are connect, you may execute any of Couchbases' numerous operations against this connection.

Here is a simple example of instantiating a connection, setting a new document into the bucket and then retrieving its contents:

  $cluster = new CouchbaseCluster('192.168.7.26');
  $db = $cluster->openBucket('default');
  $db->upsert('testdoc', array('name'=>'Frank'));
  $res = $db->get('testdoc');
  var_dump($res->value);
  // array(1) {
  //   ["name"]=>
  //   string(5) "Frank"
  // }

Documentation

An extensive documentation is available on the Couchbase website. Visit our PHP Community on the Couchbase website for the documentation as well as numerous examples and samples.

Source Control

The source code is available at https://github.com/couchbaselabs/php-couchbase.

To execute our test suite, simply install and execute phpunit against your checked out source code.

License

Copyright 2013 Couchbase Inc.

Licensed under the Apache License, Version 2.0.

See LICENSE for further details.

php-couchbase's People

Contributors

brett19 avatar chippiewill avatar jarro avatar jdubreville avatar jordymoos avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

php-couchbase's Issues

Memory leak on bucket commands

Hey Brett19

I think you have a memory leak in the bucket commands. If i run the sample script below then i would expect that 'Done' will be printen eventually. But after about 35.000 rows the script will be out of memory and stop.

Maybe you are not clearing the data of the document?

<?php

error_reporting(E_ALL);
ini_set('display_errors', true);

ini_set('memory_limit', '32M');

$cluster = new \CouchbaseCluster('localhost');
$bucket = $cluster->openBucket('test');

for ($i = 1; $i <= 1000000; $i++) {
    if ($i % 1000 == 0) {
        echo $i . PHP_EOL;
    }

    $bucket->upsert((string) $i, md5($i));
}

echo 'Done';

error: use of undeclared identifier 'LCB_HTTP_TYPE_N1QL'

If i want to install couchbase 2.0.7 via
pecl install couchbase

Then i will get something like this:

creating libtool
appending configuration tag "CXX" to libtool
configure: creating ./config.status
config.status: creating config.h
running: make
/bin/sh /private/var/folders/gn/_6lp39nn4p10f0kx6m1x7nx00000gn/T/pear/temp/pear-build-jordymoosLza6YV/couchbase-2.0.7/libtool --mode=compile cc  -I. -I/private/var/folders/gn/_6lp39nn4p10f0kx6m1x7nx00000gn/T/pear/temp/couchbase -DPHP_ATOM_INC -I/private/var/folders/gn/_6lp39nn4p10f0kx6m1x7nx00000gn/T/pear/temp/pear-build-jordymoosLza6YV/couchbase-2.0.7/include -I/private/var/folders/gn/_6lp39nn4p10f0kx6m1x7nx00000gn/T/pear/temp/pear-build-jordymoosLza6YV/couchbase-2.0.7/main -I/private/var/folders/gn/_6lp39nn4p10f0kx6m1x7nx00000gn/T/pear/temp/couchbase -I/usr/local/Cellar/php55/5.5.24/include/php -I/usr/local/Cellar/php55/5.5.24/include/php/main -I/usr/local/Cellar/php55/5.5.24/include/php/TSRM -I/usr/local/Cellar/php55/5.5.24/include/php/Zend -I/usr/local/Cellar/php55/5.5.24/include/php/ext -I/usr/local/Cellar/php55/5.5.24/include/php/ext/date/lib  -DHAVE_CONFIG_H  -g -O2   -c /private/var/folders/gn/_6lp39nn4p10f0kx6m1x7nx00000gn/T/pear/temp/couchbase/bucket.c -o bucket.lo
mkdir .libs
 cc -I. -I/private/var/folders/gn/_6lp39nn4p10f0kx6m1x7nx00000gn/T/pear/temp/couchbase -DPHP_ATOM_INC -I/private/var/folders/gn/_6lp39nn4p10f0kx6m1x7nx00000gn/T/pear/temp/pear-build-jordymoosLza6YV/couchbase-2.0.7/include -I/private/var/folders/gn/_6lp39nn4p10f0kx6m1x7nx00000gn/T/pear/temp/pear-build-jordymoosLza6YV/couchbase-2.0.7/main -I/private/var/folders/gn/_6lp39nn4p10f0kx6m1x7nx00000gn/T/pear/temp/couchbase -I/usr/local/Cellar/php55/5.5.24/include/php -I/usr/local/Cellar/php55/5.5.24/include/php/main -I/usr/local/Cellar/php55/5.5.24/include/php/TSRM -I/usr/local/Cellar/php55/5.5.24/include/php/Zend -I/usr/local/Cellar/php55/5.5.24/include/php/ext -I/usr/local/Cellar/php55/5.5.24/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /private/var/folders/gn/_6lp39nn4p10f0kx6m1x7nx00000gn/T/pear/temp/couchbase/bucket.c  -fno-common -DPIC -o .libs/bucket.o
/private/var/folders/gn/_6lp39nn4p10f0kx6m1x7nx00000gn/T/pear/temp/couchbase/bucket.c:1036:13: error: use of undeclared identifier 'LCB_HTTP_TYPE_N1QL'
            type = LCB_HTTP_TYPE_N1QL;
                   ^
1 error generated.
make: *** [bucket.lo] Error 1
ERROR: `make' failed

Couchbase\Bucket::query

Couchbase\Bucket::query($query, $jsonAsArray = false) method
doesn't respect $jsonAsArray param
and always return stdClass object
it works correctly in 2.2.4 and works incorectly in all versions above that

code:

$cluster = new \CouchbaseCluster($dsn);
$bucket = $cluster->openBucket($config['bucket'], $config['password']);

$query = \CouchbaseViewQuery::from('media_event', 'aggregate')
    ->reduce(true)
    ->group(true)
    ->range([$clientName, $from->format('Y-m-d')], [$clientName, $to->format('Y-m-d')], true);

$result = $bucket->query($query, true);
var_dump($result);

$result = $bucket->query($query, false);
var_dump($result);

produces:

object(stdClass)#2435 (1) {
  ["rows"]=>
  array(0) {
  }
}
object(stdClass)#2435 (1) {
  ["rows"]=>
  array(0) {
  }
}

but should be:

array(1) {
  ["rows"]=>
  array(0) {
  }
}
object(stdClass)#2435 (1) {
  ["rows"]=>
  array(0) {
  }
}

libcouchbase with createBucket

Hello

I am experiencing an issue with the method CouchbaseClusterManager::createBucket:

FATAL ERROR:
libcouchbase experienced an unrecoverable error and terminates the program
to avoid undefined behavior.
The program should have generated a "corefile" which may used
to gather more information about the problem.
If your system doesn't create "corefiles" I can tell you that the
assertion failed in /tmp/buildd/libcouchbase-2.5.4/src/bucketconfig/confmon.c at line 293

Here is the PHP code:

$adminUsername = 'Administrator';
$adminPassword = 'mySuperP@ssw0rd';
$cluster = new \CouchbaseCluster('couchbase://localhost', $adminUsername, $adminPassword);
$bucketManager = $cluster->manager($adminUsername, $adminPassword);

$bucketManager->createBucket('plop', [
    'authType' => 'sasl',
    'bucketType' => 'couchbase',
    'flushEnabled' => true,
    'ramQuotaMB' => 200
 ]);

The documentation of the PHP client does not mention anything about the method options. So I tried to use the options described in the REST API documentation.

System informations:

Thank you for your help.

adhoc must be a bool

I am getting the above error when using N1QL to do a DELETE FROM query. I also get this error on the couchbase/php-couchbase master branch, but not on the v2.1 tag of that repo when using PHP 5.6. I am running on OSX el Capitan using brew PHP 7.0.5

Client side timeout exception

Hi i've been trying to google for an answer to my problem, but I had no luck.

I have setup the CB server on AWS EC ubuntu, it is working since i can play around with it on the said machine, but when i try to connect on my local server, it is always showing timeout exception:

I've tried what the documentation said:
1)

$cc = new \CouchbaseCluster('http://mydomain.com', 'user', 'password')

-> not working
using IP
2)

$cc = new \CouchbaseCluster('couchbase://52.16.45.7', 'user', 'password')

-> not working
using with port

8091

on each one, still not working but using '

couchbase://localhost

' will work only if i execute the query within the server.

Any idea what i've done wrong? thanks.

Bug in new CouchbaseBucket()

Hi, Brett, how are you?

Some error text:

( ! ) Fatal error: Uncaught exception 'CouchbaseException' with message 'Invalid arguments' in [CouchbaseNative]/CouchbaseBucket.class.php on line 74
( ! ) CouchbaseException: Invalid arguments in [CouchbaseNative]/CouchbaseBucket.class.php on line 74
Call Stack
#   Time    Memory  Function    Location
1   0.0007  459280  {main}( )   ../index.php:0
2   0.0009  461832  CouchbaseCluster->openBucket( ) ../index.php:9
3   0.0010  463248  CouchbaseBucket->__construct( ) ../CouchbaseCluster.class.php:61
4   0.0012  463664  __construct ( ) ../CouchbaseBucket.class.php:74

My code is:

$cluster = new CouchbaseCluster();
$db = $cluster->openBucket();

Steps:

  1. Compiled https://github.com/couchbase/libcouchbase
  2. Then https://github.com/couchbase/php-couchbase 2.1.0 (and also tried on 2.0.7)

System: osx 10.9.5
PHP: 5.6.10
Couchbase: Version 4.0.0-4051

P.S. This https://github.com/couchbase/php-ext-couchbase works fine

What should i do to fix it?
Regards, Vasily

getDesignDocuments error with Couchbase 3

Hello. Looks like getDesignDocuments function returns:

Notice: Undefined index: meta in [CouchbaseNative]/CouchbaseBucketManager.class.php on line 53
Notice: Undefined index: json in [CouchbaseNative]/CouchbaseBucketManager.class.php on line 54
Notice: Undefined index: meta in [CouchbaseNative]/CouchbaseBucketManager.class.php on line 53
Notice: Undefined index: json in [CouchbaseNative]/CouchbaseBucketManager.class.php on line 54

Is this lib version compatible with Couchbase server 3 ?

Looks like in 3 version you have additionally doc/controllers structure https://www.dropbox.com/s/mfk9d304ugcrzcu/Screenshot%202014-12-12%2018.55.10.png?dl=0

Fatal error while calling CouchbaseBucket->get

I have php code using php-couchbase working well on my webUI. However I noticed an issue since upgrading to php-couchbase 2.1.0 release. It seems to crash when I try to get a deleted / non-existent document.
Code that gives fatal error -

$record=$this->bucket->get($docid);
PHP Fatal error: Cannot use object of type stdClass as array in [CouchbaseNative]/CouchbaseBucket.class.php on line 284

Expected result -
CouchbaseException thrown indicating the record does not exist. Does the fact that the document in question was deleted make a difference? In any case it calls for some further sanity checks in the CouchbaseBucket.class.php to avoid fatal errors in unexpected conditions.

Configurable error mode

I was wondering if there were any plans to make the extensions' behaviour configurable in the event of certain errors. For example: when retrieving a bunch of documents in a loop like so:

$docs = [];
for ($i=0;$i<100;++$i)
    $docs[] = $bucket->get('document::' . $i);

At the moment, the extension throws an exception whenever a document doesn't exist. It would be useful, IMO, to call a method that changes this behaviour (ie, have the get call return null when a document is not found instead).

I've taken a quick look at the code, and I'm happy to implement this feature myself (so far, I've only added 2 methods: https://github.com/EVODelavega/php-couchbase/tree/remote-master), but the way this extension is built is a bit odd in places (with the stubs being an actual integral part of the extension and all that...).
Is there any documentation available for people wanting to contribute to this project?

Thanks

Version 2.0.8

Hey Brett!

Can a new version be released with the exception memory leak fix?

Cheers!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.