-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcouchbaseAPI.php
1175 lines (1030 loc) · 40.8 KB
/
couchbaseAPI.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* The content of this file is a description of the Couchbase API, so that you
* may configure your IDE for code completion, documentation and constants.
*/
////////////////////////////////////////////////////////
// //
// The following error codes exist //
// //
////////////////////////////////////////////////////////
/**
* Everything is OK.
*/
const COUCHBASE_SUCCESS = 0x00; //LCB_SUCCESS
/**
* This is an internal error message.
*/
const COUCHBASE_AUTH_CONTINUE = 0x01; //LCB_AUTH_CONTINUE
/**
* Increment/decrement on an object that isn't a number.
*/
const COUCHBASE_DELTA_BADVAL = 0x03; //LCB_DELTA_BADVAL
/**
* The object is too big to be stored on the server.
*/
const COUCHBASE_E2BIG = 0x04; //LCB_E2BIG
/**
* The server is too busy to handle your request. Please try again later.
*/
const COUCHBASE_EBUSY = 0x05; //LCB_EBUSY
/**
* An internal error in the Couchbase extension.
* You should probably submit a bug report for this.
*/
const COUCHBASE_EINTERNAL = 0x06; //LCB_EINTERNAL
/**
* Out of resources.
*/
const COUCHBASE_ENOMEM = 0x08; //LCB_ENOMEM
/**
* Generic error code.
*/
const COUCHBASE_ERROR = 0x0a; //LCB_ERROR
/**
* Temporarily cannot handle request. A later retry may succeed.
*/
const COUCHBASE_ETMPFAIL = 0x0b; //LCB_ETMPFAIL
/**
* The key exists, but the CAS identifier provided did not match the one for
* the object in the cluster.
*/
const COUCHBASE_KEY_EEXISTS = 0x0c; //LCB_KEY_EEXISTS
/**
* The key does not exist.
*/
const COUCHBASE_KEY_ENOENT = 0x0d; //LCB_KEY_ENOENT
/**
* An error occurred while trying to read/write data to the network.
*/
const COUCHBASE_NETWORK_ERROR = 0x10; //LCB_NETWORK_ERROR
/**
* The command was sent to the wrong server. This problem may occur if
* someone added/removed a node to the cluster. Retrying the operation may
* solve the problem.
*/
const COUCHBASE_NOT_MY_VBUCKET = 0x11; //LCB_NOT_MY_VBUCKET
/**
* The document was not stored.
*/
const COUCHBASE_NOT_STORED = 0x12; //LCB_NOT_STORED
/**
* The server knows about this command, but the datastore doesn't support it
* for some reason.
*/
const COUCHBASE_NOT_SUPPORTED = 0x13; //LCB_NOT_SUPPORTED
/**
* The server did not understand the command we sent. This may occur if you
* are attempting to use an operation not supported on an older version of
* Couchbase Server.
*/
const COUCHBASE_UNKNOWN_COMMAND = 0x14; //LCB_UNKNOWN_COMMAND
/**
* Failed to lookup the host.
*/
const COUCHBASE_UNKNOWN_HOST = 0x15; //LCB_UNKNOWN_HOST
////////////////////////////////////////////////////////
// //
// The following option constants exist //
// //
////////////////////////////////////////////////////////
/**
* Specifies the serializer to use to store objects in the cluster.
*/
const COUCHBASE_OPT_SERIALIZER = 1;
/**
* Specifies the compression to use for big objects.
*/
const COUCHBASE_OPT_COMPRESSION = 2;
/**
* A text string used as a prefix for all keys (may be used to create your
* own namespace).
*/
const COUCHBASE_OPT_PREFIX_KEY = 3;
/**
* This option is used to disable the deserialisation of the
* data received from the cluster. It is mainly used by the
* developers of the extension to be able to test variable
* parts of the API and should not be used by end users
* (it may be removed without notice if we find a better way to do
* this).
*/
const COUCHBASE_OPT_IGNOREFLAGS = 4;
/**
* @todo figure out what this is used for...
*/
const COUCHBASE_OPT_VOPTS_PASSTHROUGH = 5;
/**
* Constant representing the PHP serializer.
*/
const COUCHBASE_SERIALIZER_PHP = 0;
/**
* Constant representing the JSON serializer.
*/
const COUCHBASE_SERIALIZER_JSON = 1;
/**
* Constant representing the JSON serializer, but deserialise into arrays.
*/
const COUCHBASE_SERIALIZER_JSON_ARRAY = 2;
/**
* Constant representing no compression.
*/
const COUCHBASE_COMPRESSION_NONE = 0;
/**
* Constant representing zlib compression.
*/
const COUCHBASE_COMPRESSION_ZLIB = 1;
/**
* Constant representing fastlz compression.
*/
const COUCHBASE_COMPRESSION_FASTLZ = 2;
/**
* Constant representing preserve order for multiget
*/
const COUCHBASE_PRESERVE_ORDER = 1;
////////////////////////////////////////////////////////
// //
// The following replica strategies exist //
// //
////////////////////////////////////////////////////////
/**
* The caller will get a reply from the first replica to successfully
* reply within the timeout for the operation or will receive an
* error.
*/
const COUCHBASE_REPLICA_FIRST = LCB_REPLICA_FIRST;
/**
* Ask all replicas to send documents/items back. The order of the
* replicas does not imply anything and is just the order they are
* received from the servers (one server may be more busy than
* the other etc).
*/
const COUCHBASE_REPLICA_ALL = LCB_REPLICA_ALL;
/**
* Select one replica by the index in the configuration starting from
* zero. This approach can more quickly receive all possible replies
* for a given topology, but it can also generate false negatives
*/
const COUCHBASE_REPLICA_SELECT = LCB_REPLICA_SELECT;
/**
* A class representing a connection to a Couchbase bucket.
*/
class Couchbase {
/**
* Constructs a new instance of a Couchbase object.
*
* @param array $hosts An array of hostnames[:port] where the
* Couchbase cluster is running. The port number is
* optional (and only needed if you're using a non-
* standard port).
* @param string $user The username used for authentication to
* the cluster
* @param string $password The password used to authenticate to
* the cluster
* @param string $bucket The name of the bucket to connect to
* @param boolean $persistent If a persistent object should be used or not
*/
function __construct($hosts = array("localhost"), $user = "", $password = "", $bucket = "default", $persistent = true) {
}
/**
* Add a document to the cluster.
*
* The add operation adds a document to the cluster only if no document
* exists in the cluster with the same identifier.
*
* @param string $id the identifier to store the document under
* @param object $document the document to store
* @param integer $expiry the lifetime of the document (0 == infinite)
* @param integer $persist_to wait until the document is persisted to (at least)
* this many nodes
* @param integer $replicate_to wait until the document is replicated to (at least)
* this many nodes
* @return string the cas value of the object if success
* @throws CouchbaseException if an error occurs
*/
function add($id, $document, $expiry = 0, $persist_to = 0, $replicate_to = 0) {
}
/**
* Store a document in the cluster.
*
* The set operation stores a document in the cluster. It differs from
* add and replace in that it does not care for the presence of
* the identifier in the cluster.
*
* If the $cas field is specified, set will <b>only</b> succeed if the
* identifier exists in the cluster with the <b>exact</b> same cas value
* as the one specified in this request.
*
* @param string $id the identifier to store the document under
* @param object|string $document the document to store
* @param integer $expiry the lifetime of the document (0 == infinite)
* @param string $cas a cas identifier to restrict the store operation
* @param integer $persist_to wait until the document is persisted to (at least)
* this many nodes
* @param integer $replicate_to wait until the document is replicated to (at least)
* this many nodes
* @return string the cas value of the object if success
* @throws CouchbaseException if an error occurs
*/
function set($id, $document, $expiry = 0, $cas = "", $persist_to = 0, $replicate_to = 0) {
}
/**
* Store multiple documents in the cluster.
*
* @param array $documents an array containing "id" => "document" pairs
* @param integer $expiry the lifetime of the document (0 == infinite)
* @param integer $persist_to wait until the document is persisted to (at least)
* this many nodes
* @param integer $replicate_to wait until the document is replicated to (at least)
* this many nodes
* @return boolean true if success
* @throws CouchbaseException if an error occurs
*/
function setMulti($documents, $expiry = 0, $persist_to = 0, $replicate_to = 0) {
}
/**
* Replace a document in the cluster.
*
* The replace operation replaces an existing document in the cluster.
* It differs from add and set in the way that it requires the precense of
* the identifier in the cluster.
*
* If the $cas field is specified set will <b>only</b> succeed if the
* identifier exists in the cluster with the <b>exact</b> same cas value
* as the one specified in this request.
*
* @param string $id the identifier to store the document under
* @param object $document the document to store
* @param integer $expiry the lifetime of the document (0 == infinite)
* @param string $cas a cas identifier to restrict the replace operation
* @param integer $persist_to wait until the document is persisted to (at least)
* this many nodes
* @param integer $replicate_to wait until the document is replicated to (at least)
* this many nodes
* @return string the cas value of the object if success
* @throws CouchbaseException if an error occurs
*/
function replace($id, $document, $expiry = 0, $cas = "", $persist_to = 0, $replicate_to = 0) {
}
/**
* Prepend a document to another document.
*
* The prepend operation prepends the attached document to the document
* already stored in the cluster.
*
* If the $cas field is specified prepend will <b>only</b> succeed if the
* identifier exists in the cluster with the <b>exact</b> same cas value
* as the one specified in this request.
*
* @param string $id identifies the document
* @param object $document the document to prepend
* @param integer $expiry the lifetime of the document (0 == infinite)
* @param string $cas a cas identifier to restrict the prepend operation
* @param integer $persist_to wait until the document is persisted to (at least)
* this many nodes
* @param integer $replicate_to wait until the document is replicated to (at least)
* this many nodes
* @return string the cas value of the object if success
* @throws CouchbaseException if an error occurs
*/
function prepend($id, $document, $expiry = 0, $cas = "", $persist_to = 0, $replicate_to = 0) {
}
/**
* Append a document to another document.
*
* The append operation appends the attached document to the document
* already stored in the cluster.
*
* If the $cas field is specified append will <b>only</b> succeed if the
* identifier exists in the cluster with the <b>exact</b> same cas value
* as the one specified in this request.
*
* @param string $id identifies the document
* @param object $document the document to append
* @param integer $expiry the lifetime of the document (0 == infinite)
* @param string $cas a cas identifier to restrict the append operation
* @param integer $persist_to wait until the document is persisted to (at least)
* this many nodes
* @param integer $replicate_to wait until the document is replicated to (at least)
* this many nodes
* @return string the cas value of the object if success
* @throws CouchbaseException if an error occurs
*/
function append($id, $document, $expiry = 0, $cas = "", $persist_to = 0, $replicate_to = 0) {
}
/**
* Please use replace with the $cas field specified.
*/
function cas($cas, $id, $document, $expiry) {
}
/**
* Retrieve a document from the cluster.
*
* @param string $id identifies the object to retrieve
* @param callable $callback a callback function to call for missing
* objects. The function signature looks like:
* <code>bool function($res, $id, &$val)</code>
* if the function returns <code>true</code> the value
* returned through $val is returned. Please note that
* the cas field is not updated in these cases.
* @param string $cas where to store the cas identifier of the object
* @return object The document from the cluster
* @throws CouchbaseException if an error occurs
*/
function get($id, $callback = NULL, &$cas = "") {
}
/**
* Retrieve multiple documents from the cluster.
*
* @param array $ids an array containing all of the document identifiers
* @param array $cas an array to store the cas identifiers of the documents
* @param int $flags may be 0 or COUCHBASE_GET_PRESERVE_ORDER
* @return array an array containing the documents
* @throws CouchbaseException if an error occurs
*/
function getMulti($ids, &$cas = array(), $flags = 0) {
}
/**
* Retrieve a replica of a document from the cluster.
*
* Examples:
* <code>
* $obj = $cb->getReplica("key",
* array("strategy" => COUCHBASE_REPLICA_SELECT,
* "index" => 0));
*
* returns
* [ "foo" => [ "value" => "bar", "cas" => 0] ]
*
*
* $obj = $cb->getReplica("foo", COUCHBASE_REPLICA_ALL);
*
* returns
* [ "foo" => [ [ "value" => "bar", "cas" => 0],
* [ "value" => "bar", "cas" => 0] ]
* ]
*
*
* $obj = $cb->getReplica(array("foo", "bar"), COUCHBASE_REPLICA_ALL);
*
* returns
* [ "foo" => [ [ "value" => "bar", "cas" => 0],
* [ "value" => "bar", "cas" => 0] ],
* "bar" => [ [ "value" => "val", "cas" => 0],
* [ "value" => "val", "cas" => 0] ]
* ]
*
* </code>
*
* @param string $ids The document id(s) to get. Pass an array to
* retrieve multiple documets
* @param string $strategy Which strategy to use to pick the replica.
* Pass in an array to specify extra options
* to the strategy.
* @return object The document from the cluster
* @throws CouchbaseException if an error occurs
*/
function getReplica($id, $strategy = COUCHBASE_REPLICA_FIRST) {
}
/**
* Retrieve an object from the cache and lock it from modifications.
*
* While the object is locked it may only be modified by providing the
* cas field returned in the cas field. Modifying the object automatically
* unlocks the object. To manually unlock the object use the unlock()
* method. All locks is automatically released after a configurable (on the
* cluster) time interaval.
*
* @param string $id identifies the document
* @param string $cas where to store the cas identifier
* @param integer $expiry a configuratble lock expiry time (0 == use the
* value configured on the server).
* @return object The requested document from the cluster
* @throws CouchbaseException if an error occurs
*/
function getAndLock($id, &$cas = "", $expiry = 0) {
}
/**
* Retrieve and lock multiple documents from the cache.
*
* While the object is locked it may only be modified by providing the
* cas field returned in the cas field. Modifying the object automatically
* unlocks the object. To manually unlock the object use the unlock()
* method. All locks is automatically released after a configurable (on the
* cluster) time interaval.
*
* Bear in mind that locking multiple objects at the same time may not be
* a good idea and may lead to deadlock ;-)
*
* @param array $ids an array containing the identifiers to retrieve
* @param array $cas where to store the cas identifier
* @param int $flags TODO update document for this param
* @param integer $expiry a configuratble lock expiry time (0 == use the
* value configured on the server).
* @return array an array containint the requested documents
* @throws CouchbaseException if an error occurs
*/
function getAndLockMulti($ids, &$cas = array(), $flags = 0, $expiry = 0) {
}
/**
* Retrieve a document from the cluster and update its time to live.
*
* @param string $id identifies the document
* @param integer $expiry the new time to live (0 == infinite)
* @param string $cas where to store the cas identifier
* @return object The requested document from the cluster
* @throws CouchbaseException if an error occurs
*/
function getAndTouch($id, $expiry = 0, &$cas = "") {
}
/**
* Retrieve multiple documents from the cluster and update their time to live.
*
* @param array $ids an array containint the document identifiers
* @param integer $expiry the new time to live (0 == infinite)
* @param array $cas where to store the cas identifier
* @return array an array containing the requested documents
* @throws CouchbaseException if an error occurs
*/
function getAndTouchMulti($ids, $expiry = 0, &$cas = array()) {
}
/**
* Unlock a previously locked document.
*
* @param string $id the document to unlock
* @param string $cas the cas value obtained from getAndLock()
* @return boolean true upon success
* @throws CouchbaseException if an error occurs
*/
function unlock($id, $cas) {
}
/**
* Touch (update time to live) a document in the cluster.
*
* @param string $id identifies the document
* @param integer $expiry the new time to live (0 == infinite)
* @return string containing the cas value (note some servers will
* will always return "0" for the cas value)
* @throws CouchbaseException if an error occurs
*/
function touch($id, $expiry) {
}
/**
* Touch (update time to live) multiple documents in the cluster.
*
* @param array $ids an array containing the document identifiers
* @param integer $expiry the new time to live (0 == infinite)
* @return boolean true upon success
* @throws CouchbaseException if an error occurs
*/
function touchMulti($ids, $expiry) {
}
/**
* Delete a document from the cluster.
*
* @param string $id the document identifier
* @param string $cas a cas identifier to restrict the store operation
* @param integer $persist_to wait until the document is persisted to (at least)
* this many nodes
* @param integer $replicate_to wait until the document is replicated to (at least)
* this many nodes
* @return string the cas value representing the delete document if success
* @throws CouchbaseException if an error occurs
*/
function delete($id, $cas = "", $persist_to = 0, $replicate_to = 0) {
}
/**
* Increment a numeric value in the cluster.
*
* If the value isn't created by using increment / decrement, it has to
* be created as a "textual" string like:
* <code>$cb->add("mycounter", "0");</code>. The reason for this is
* that the operation is performed in the cluster and it has to know
* the datatype in order to perform the operation.
*
* @param string $id the document identifier
* @param integer $delta the amount to increment
* @param boolean $create should the value be created if it doesn't exist
* @param integer $expire the time to live for the document (0 == infinite)
* @param integer $initial the initial value for the counter if it doesn't exist
* @return integer the new value upon success
* @throws CouchbaseException if an error occurs
*/
function increment($id, $delta = 1, $create = false, $expire = 0, $initial = 0) {
}
/**
* Decrement a numeric value in the cluster.
*
* If the value isn't created by using increment / decrement, it has to
* be created as a "textual" string like:
* <code>$cb->add("mycounter", "0");</code>. The reason for this is
* that the operation is performed in the cluster and it has to know
* the datatype in order to perform the operation.
*
* @param string $id the document identifier
* @param integer $delta the amount to decrement
* @param boolean $create should the value be created if it doesn't exist
* @param integer $expire the time to live for the document (0 == infinite)
* @param integer $initial the initial value for the counter if it doesn't exist
* @return integer the new value upon success
* @throws CouchbaseException if an error occurs
*/
function decrement($id, $delta = 1, $create = false, $expire = 0, $initial = 0) {
}
/**
* Delete all documents in the bucket.
*
* Please note that flush is disabled from the server by default, so it
* must explicitly be enabled on the bucket. Flush also require the object
* to be used to contain all the credentials (username, password and
* bucket name).
*
* @return boolean true upon success
* @throws CouchbaseException if an error occurs
*/
function flush() {
}
/**
* Issue a get request, but do not wait for responses.
*
* @param array $ids the document identifiers to retrieve
* @param boolean $with_cas if the cas identifier should be retrieved
* @param callable $callback function to call per retrieved document
* @param integer $expiry lock expiry time
* @param boolean $lock if the documents should be locked or not
* @return boolean true upon success, false otherwise
* @throws CouchbaseException if an error occurs
*/
function getDelayed($ids, $with_cas = false, $callback = null, $expiry = 0, $lock = false) {
}
/**
* Fetch the one of the received documents requested from getDelayed.
*
* @return array an array representing the next document retrieved,
* or NULL if there are no more documents.
* @throws CouchbaseException if an error occurs
*/
function fetch() {
}
/**
* Fetch the one of the received documents requested from getDelayed.
*
* @return array an array representing the documents retrieved,
* or NULL if there are no more documents.
* @throws CouchbaseException if an error occurs
*/
function fetchAll() {
}
/**
* Execute a view request.
*
* The following options are recognized.
* <table border="1">
* <tr><th>Name</th><th>Datatype</th></tr>
* <tr><td>descending</td><td>boolean</td></tr>
* <tr><td>endkey</td><td>JSON value</td></tr>
* <tr><td>endkey_docid</td><td>string</td></tr>
* <tr><td>full_set</td><td>boolean</td></tr>
* <tr><td>group</td><td>boolean</td></tr>
* <tr><td>group_level</td><td>numeric</td></tr>
* <tr><td>inclusive_end</td><td>boolean</td></tr>
* <tr><td>key</td><td>JSON</td></tr>
* <tr><td>keys</td><td>JSON array</td></tr>
* <tr><td>on_error</td><td><code>continue</code> or <code>stop</code></td></tr>
* <tr><td>reduce</td><td>boolean</td></tr>
* <tr><td>stale</td><td>boolean</td></tr>
* <tr><td>skip</td><td>numeric</td></tr>
* <tr><td>limit</td><td>numeric</td></tr>
* <tr><td>startkey</td><td>JSON</td></tr>
* <tr><td>startkey_docid</td><td>string</td></tr>
* <tr><td>debug</td><td>boolean</td></tr>
* <tr><td>connection_timeout</td><td>numeric</td></tr>
* </table>
*
* @todo update the table above with a description.
* @param string $document The design document containing the view to call
* @param string $view The view to execute
* @param array $options extra options to add to the view request (see above)
* @param boolean $return_errors Should error messages be returned upon failures
* @return array an array with the result of the view request upon success,
* or an array containing an error message
* @throws CouchbaseException if an error occurs
*/
function view($document, $view = "", $options = array(), $return_errors = false) {
}
/**
* Generate a view request.
*
* @param string $document The design document containing the view to call
* @param string $view The view to execute
* @param array $options extra options to add to the view request (see view()
* for more information)
* @param boolean $return_errors Should error messages be returned upon failures
* @return string generated view request in format: "/_design/$doc/_view/$view?stale=ok&..."
* @throws CouchbaseException if an error occurs
*/
function viewGenQuery($document, $view = "", $options = array(), $return_errors = false) {
}
/**
* Retrieve statistics information from the cluster.
*
* @return array an array containing all "key" => "value" pairs upon success
* @throws CouchbaseException if an error occurs
*/
function getStats() {
}
/**
* Get the last result code from the extension internals.
*
* @return integer An error code representing the last error code as
* seen by libcouchbase
*/
function getResultCode() {
}
/**
* Get a textual representation of the last result from the extension
* internals.
*
* @return string An textual string describing last error code as
* seen by libcouchbase
*/
function getResultMessage() {
}
/**
* Update one of the tunables.
*
* The following tunables exist:
* <table border="1">
* <tr><th>Name</th><th>Description</th></tr>
* <tr><td>COUCHBASE_OPT_SERIALIZER</td><td>Specifies the serializer to
* use to store objects in the cluster. The following values may be used:
* <code>COUCHBASE_SERIALIZER_PHP</code>, <code>COUCHBASE_SERIALIZER_JSON</code>,
* <code>COUCHBASE_SERIALIZER_JSON_ARRAY</code></td></tr>
* <tr><td>COUCHBASE_OPT_COMPRESSION</td><td>Specifies the compression to
* use for big objects. It may be set to the following values:
* <code>COUCHBASE_COMPRESSION_NONE</code>, <code>COUCHBASE_COMPRESSION_FASTLZ</code>,
* <code>COUCHBASE_COMPRESSION_ZLIB</code></td></tr>
* <tr><td>COUCHBASE_OPT_PREFIX_KEY</td><td>A text string used as a prefix
* for all keys (may be used to create your own namespace).</td></tr>
* <tr><td>COUCHBASE_OPT_IGNOREFLAGS</td><td>This options is used to disable
* the deserialisation of the data received from the cluster. It is mainly
* used by the developers of the extension to be able to test variable
* parts of the API and should not be used by end users (it may be removed
* without notice if we find a better way to do this).</td></tr>
* </table>
*
* @param integer $option the option to set
* @param integer $value the new value for the option
* @throws CouchbaseException if an error occurs (e.g illegal option / value)
*/
function setOption($option, $value) {
}
/**
* Retrieve the current value of a tunable.
*
* @param integer $option the option to retrieve the value for
* @return integer The current value for a tunable. See setOption() for a
* description of the legal options to retrieve.
* @throws CouchbaseException if an error occurs (e.g illegal option)
*/
function getOption($option) {
}
/**
* Get the version numbers of the memcached servers in the cluster.
*
* This method does probably not do what you think it would do. It
* exists for compatibility with the "memcached" extension. It does
* <b>not</b> return the Couchbase version used on each node in the
* cluster, but rather an internal version number from the memcached
* nodes in the cluster.
*
* The easiest way to get the Couchbase version nodes would be
* something among the lines of:
*
* <pre>
* $cb = new CouchbaseClusterManager("localhost", "Administrator", "secret");
* $info = json_decode($cb->getInfo());
* foreach ($info->{"nodes"} as $node) {
* print $node->{"hostname"} . " is running " . $node->{"version"} . "\n";
* }
* </pre>
* @return array an array containing the memcached version on each node
* @throws CouchbaseException if an error occurs
*/
function getVersion() {
}
/**
* Retrieve the version number of the client.
*
* @return string client library version number
*/
function getClientVersion() {
}
/**
* Get the number of replicas configured for the bucket.
*
* Note that even if the bucket is configured to use this number of
* replicas doesn't necessarily mean that this number of replicas exist.
* It is possible to set the number of replicas higher than the number
* of nodes.
*
* @return integer The number of replicas for the bucket
* @throws CouchbaseException if an error occurs
*/
function getNumReplicas() {
}
/**
* Get the name of the servers in the cluster.
*
* @return array an array containing all of the servers in the cluster
* @throws CouchbaseException if an error occurs
*/
function getServers() {
}
/**
* Get information about a key in the cluster.
*
* @param string $id The identifier to get information about
* @param string $cas The cas for the document to get information about
* @param array $details an array to store the details about the key
* @todo update the documentation about the name and meaning of the details
* @return bool true on success, false otherwise
* @throws CouchbaseException if an error occurs
*/
function observe($id, $cas, &$details = array()) {
}
/**
* Get information about multiple keys in the cluster.
*
* @param array $ids an array containing the identifiers to look up
* @param array $details an array to store the details about the documents
* @return array with the keys with true on success, false otherwise
* @throws CouchbaseException if an error occurs
*/
function observeMulti($ids, &$details = array()) {
}
/**
* Wait for a document to reach a certain state.
*
* <table border="1">
* <tr><th>Name</th><th>Description</th></tr>
* <tr><td>persist_to</td><td>The number of nodes the document should be
* persisted to</td></tr>
* <tr><td>replicate_to</td><td>The number of nodes the document should be
* replicated to</td></tr>
* <tr><td>timeout</td><td>The max time to wait for durability</td></tr>
* <tr><td>interval</td><td>The interval between checking the state of
* the document</td></tr>
*
* </table>
*
* @param string $id the identifier for the document to wait for
* @param string $cas the cas identifier for the document to wait for
* @param array $details an array containing the details. see above
* @return bool true on success, false otherwise
* @throws CouchbaseException if an error occurs
*/
function keyDurability($id, $cas, $details = array()) {
}
/**
* Wait for multiple documents to reach a certain state.
*
* @param array $ids an array containing "identifier" => "cas" pairs
* @param array $details is an array containing the options to wait for.
* See keyDurability() for a description.
* @return array with the keys with true on success, false otherwise
* @throws CouchbaseException if an error occurs
*/
function keyDurabilityMulti($ids, $details = array()) {
}
/**
* Retrieve the current operation timeout.
*
* @return integer The currently used timeout specified in usec
*/
function getTimeout() {
}
/**
* Specify an operation timeout.
*
* The operation timeout is the time it takes from the command is sent
* to the cluster and the result should be returned back.
*
* @param integer $timeout the new operation timeout specified in usec
*/
function setTimeout($timeout) {
}
/**
* Get a design document from the cluster.
*
* @param string $name The design document to retrieve
* @return string the content of the document if success
* @throws CouchbaseException if an error occurs
*/
function getDesignDoc($name) {
}
/**
* Store a design document in the cluster.
*
* Please note that this method will overwrite any existing design document
* with the same name.
*
* @param string $name the name of the design document to store
* @param string $document the new document to create
* @return bool true on success
* @throws CouchbaseException if an error occurs
*/
function setDesignDoc($name, $document) {
}
/**
* Delete the named design document from the cluster.
*
* @param string $name the name of the design document to delete
* @return bool true on success
* @throws CouchbaseException if an error occurs
*/
function deleteDesignDoc($name) {
}
/**
* List all design documents for this bucket
*
* @return string A JSON encoded string containing all information about
* the design documents
* @throws CouchbaseException if an error occurs
*/
function listDesignDocs() {
}
}
/**
* A class to wrap the management of a Couchbase cluster.
*
* Provides APIs for managing a Couchbase cluster, including the creation,
* deletion and modification of buckets.
*/
class CouchbaseClusterManager {
/**
* Create a new instance of the CouchbaseClusterManager.
*
* @param array $hosts This is an array of hostnames[:port] where the
* Couchbase cluster is running. The port number is
* optional (and only needed if you're using a non-
* standard port).
* @param string $user This is the username used for authentications towards
* the cluster
* @param string $password This is the password used to authenticate towards
* the cluster
*/
function __construct($hosts, $user, $password) {
}
/**
* Get information about the cluster.
*
* @return string a JSON encoded string containing information of the
* cluster.
*/
function getInfo() {
}
/**
* Get information about one (or more) buckets.
*