Skip to content

Commit 31cf8a8

Browse files
committed
Next version of tarantool-php for php7
Features: * Rewritten update/upsert, so no more big memory overhead * Now have Exception Tree: TarantoolException -> TarantoolIOException,TarantoolParsingException,TarantoolClientError - TarantoolIOExceptions for send/recv/connect problems - TarantoolParsingException for parsing length/header/body problems - TarantoolClientError for errors happened in Tarantool * Refactoring for SchemaParsing for Update/Upsert field no.extraction (you can now use field name, instead of field number in update/upsert)
1 parent 932fd68 commit 31cf8a8

37 files changed

+23118
-25792
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Makefile.in
3434
*.libs
3535
*.pyc
3636
*.out
37+
*.dSYM
3738
var*
3839
config.guess.cdbs-orig
3940
config.sub.cdbs-orig

README.md

+67-85
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ $ make install
2626

2727
## Test
2828

29-
To run tests Taranool server and PHP/PECL package are requred.
29+
To run tests Tarantool server and PHP/PECL package are requred.
3030

3131
```sh
3232
$ ./test-run.py
@@ -42,7 +42,7 @@ $ TARANTOOL_BOX_PATH=/path/to/tarantool/bin/tarantool ./test-run.py
4242

4343
## Installing from PEAR
4444

45-
Tarantool-PHP Have it's own [PEAR repository](https://tarantool.github.io/tarantool-php).
45+
Tarantool-PHP has its own [PEAR repository](https://tarantool.github.io/tarantool-php).
4646
You may install it from PEAR with just a few commands:
4747

4848
```
@@ -66,7 +66,6 @@ Place it into project library path in your IDE.
6666
## Configuration file
6767

6868
* `tarantool.persistent` - Enable persistent connections (don't close connections between sessions) (defaults: True, **can't be changed in runtime**)
69-
* `tarantool.con_per_host` - Count of open connections to every Tarantool server to store (defaults: 5, **can't be changed in runtime**)
7069
* `tarantool.timeout` - Connection timeout (defaults: 10 seconds, can be changed in runtime)
7170
* `tarantool.retry_count` - Count of retries for connecting (defaults: 1, can be changed in runtime)
7271
* `tarantool.retry_sleep` - Sleep between connecting retries (defaults: 0.1 second, can be changed in runtime)
@@ -78,11 +77,10 @@ Place it into project library path in your IDE.
7877

7978
1. [Predefined Constants](#predefined-constants)
8079
2. [Class Tarantool](#class-tarantool)
81-
* [Tarantool::_construct](#tarantool__construct)
80+
* [Tarantool::__construct](#tarantool__construct)
8281
3. [Manipulation connection](#manipulation-connection)
8382
* [Tarantool::connect](#tarantoolconnect)
8483
* [Tarantool::disconnect](#tarantooldisconnect)
85-
* [Tarantool::authenticate](#tarantoolauthenticate)
8684
* [Tarantool::flushSchema](#tarantoolflushschema)
8785
* [Tarantool::ping](#tarantoolping)
8886
4. [Database queries](#database-queries)
@@ -98,45 +96,44 @@ Place it into project library path in your IDE.
9896

9997
_**Description**_: Available Tarantool Constants
10098

101-
* `TARANTOOL_ITER_EQ` - Equality iterator (ALL)
102-
* `TARANTOOL_ITER_REQ` - Reverse equality iterator
103-
* `TARANTOOL_ITER_ALL` - Get all rows
104-
* `TARANTOOL_ITER_LT` - Less then iterator
105-
* `TARANTOOL_ITER_LE` - Less and equal iterator
106-
* `TARANTOOL_ITER_GE` - Greater and equal iterator
107-
* `TARANTOOL_ITER_GT` - Gtreater then iterator
108-
* `TARANTOOL_ITER_BITSET_ALL_SET` - check if all given bits are set (BITSET only)
109-
* `TARANTOOL_ITER_BITSET_ANY_SET` - check if any given bits are set (BITSET only)
110-
* `TARANTOOL_ITER_BITSET_ALL_NOT_SET` - check if all given bits are not set
99+
* `Tarantool::ITERATOR_EQ` - Equality iterator (ALL)
100+
* `Tarantool::ITERATOR_REQ` - Reverse equality iterator
101+
* `Tarantool::ITERATOR_ALL` - Get all rows
102+
* `Tarantool::ITERATOR_LT` - Less then iterator
103+
* `Tarantool::ITERATOR_LE` - Less and equal iterator
104+
* `Tarantool::ITERATOR_GE` - Greater and equal iterator
105+
* `Tarantool::ITERATOR_GT` - Gtreater then iterator
106+
* `Tarantool::ITERATOR_BITS_ALL_SET` - check if all given bits are set (BITSET only)
107+
* `Tarantool::ITERATOR_BITS_ANY_SET` - check if any given bits are set (BITSET only)
108+
* `Tarantool::ITERATOR_BITS_ALL_NOT_SET` - check if all given bits are not set
111109
(BITSET only)
112-
* `TARANTOOL_ITER_OVERLAPS` - find dots in the n-dimension cube (RTREE only)
113-
* `TARANTOOL_ITER_NEIGHBOR` - find nearest dots (RTREE only)
110+
* `Tarantool::ITERATOR_OVERLAPS` - find dots in the n-dimension cube (RTREE only)
111+
* `Tarantool::ITERATOR_NEIGHBOR` - find nearest dots (RTREE only)
114112

115113
### Class Tarantool
116114

117115
``` php
118116
Tarantool {
119-
public Tarantool::__construct ( [ string $host = 'localhost' [, int $port = 3301 ] ] )
120-
public bool Tarantool::connect ( void )
121-
public bool Tarantool::disconnect ( void )
122-
public Tarantool::authenticate(string $login [, string $password = NULL ] )
123-
public bool Tarantool::flushSchema ( void )
124-
public bool Tarantool::ping ( void )
125-
public array Tarantool::select(mixed $space [, mixed $key = array() [, mixed $index = 0 [, int $limit = PHP_INT_MAX [, int offset = 0 [, iterator = TARANTOOL_ITER_EQ ] ] ] ] ] )
126-
public array Tarantool::insert(mixed $space, array $tuple)
127-
public array Tarantool::replace(mixed $space, array $tuple)
128-
public array Tarantool::call(string $procedure [, mixed args])
129-
public array Tarantool::evaluate(string $expression [, mixed args])
130-
public array Tarantool::delete(mixed $space, mixed $key [, mixed $index])
131-
public array Tarantool::update(mixed $space, mixed $key, array $ops [, number $index] )
132-
public array Tarantool::upsert(mixed $space, mixed $key, array $ops [, number $index] )
117+
public Tarantool::__construct ( [ string $host = 'localhost' [, int $port = 3301 [, string $user = "guest" [, string $password = NULL [, string $persistent_id = NULL ] ] ] ] ] )
118+
public bool Tarantool::connect ( void )
119+
public bool Tarantool::disconnect ( void )
120+
public bool Tarantool::flushSchema ( void )
121+
public bool Tarantool::ping ( void )
122+
public array Tarantool::select (mixed $space [, mixed $key = array() [, mixed $index = 0 [, int $limit = PHP_INT_MAX [, int $offset = 0 [, $iterator = Tarantool::ITERATOR_EQ ] ] ] ] ] )
123+
public array Tarantool::insert (mixed $space, array $tuple)
124+
public array Tarantool::replace (mixed $space, array $tuple)
125+
public array Tarantool::call (string $procedure [, mixed args] )
126+
public array Tarantool::evaluate (string $expression [, mixed args] )
127+
public array Tarantool::delete (mixed $space, mixed $key [, mixed $index] )
128+
public array Tarantool::update (mixed $space, mixed $key, array $ops [, number $index] )
129+
public array Tarantool::upsert (mixed $space, mixed $key, array $ops [, number $index] )
133130
}
134131
```
135132

136-
#### Taratnool::__construct
133+
#### Tarantool::__construct
137134

138135
```
139-
public Tarantool::__construct ( [ string $host = 'localhost' [, int $port = 3301 ] ] )
136+
public Tarantool::__construct ( [ string $host = 'localhost' [, int $port = 3301 [, string $user = "guest" [, string $password = NULL [, string $persistent_id = NULL ] ] ] ] ] )
140137
```
141138

142139
_**Description**_: Creates a Tarantool client
@@ -145,6 +142,10 @@ _**Parameters**_
145142

146143
* `host`: string, default is `'localhost'`
147144
* `port`: number, default is `3301`
145+
* `user`: string, default is `'guest'`
146+
* `password`: string
147+
* `persistent_id`: string (set it, and connection will be persistent, if
148+
`persistent` in config isn't set)
148149

149150
_**Return Value**_
150151

@@ -187,36 +188,6 @@ _**Return Value**_
187188

188189
**BOOL**: True
189190

190-
### Tarantool::authenticate
191-
192-
``` php
193-
public Tarantool::authenticate(string $login [, string $password = NULL ] )
194-
```
195-
196-
_**Description**_: Authenticate to Tarantool using given login/password
197-
198-
_**Parameters**_
199-
200-
* `login`: string - user login (mandatory)
201-
* `password`: string - user password (mandatory, but ignored, if user is guest)
202-
203-
_**Return Value**_ NULL
204-
205-
#### *Example*
206-
207-
``` php
208-
/**
209-
* - user is 'valdis'
210-
* - password is 'pelsh'
211-
*/
212-
$tnt->connect('valdis', 'pelsh')
213-
/**
214-
* - user is 'guest'
215-
* - password is empty and ignored, anyway
216-
*/
217-
$tnt->connect('guest')
218-
```
219-
220191
### Tarantool::flushSchema
221192

222193
``` php
@@ -248,7 +219,7 @@ Throws `Exception` on error.
248219
### Tarantool::select
249220

250221
``` php
251-
public array Tarantool::select(mixed $space [, mixed $key = array() [, mixed $index = 0 [, int $limit = PHP_INT_MAX [, int offset = 0 [, iterator = TARANTOOL_ITER_EQ ] ] ] ] ] )
222+
public array Tarantool::select(mixed $space [, mixed $key = array() [, mixed $index = 0 [, int $limit = PHP_INT_MAX [, int $offset = 0 [, $iterator = Tarantool::ITERATOR_EQ ] ] ] ] ] )
252223
```
253224

254225
_**Description**_: Execute select query from Tarantool server.
@@ -262,7 +233,11 @@ _**Parameters**_
262233
* `limit`: Number, limit number of rows to return from select (INT_MAX by default)
263234
* `offset`: Number, offset to select from (0 by default)
264235
* `iterator`: Constant, iterator type. See [Predefined Constants](#predefined-constants)
265-
for more information (`TARANTOOL_ITER_EQ` by default)
236+
for more information (`Tarantool::ITERATOR_EQ` by default). You can also use
237+
strings `'eq'`, `'req'`, `'all'`, `'lt'`, `'le'`, `'ge'`, `'gt'`,
238+
`'bits_all_set'`, `'bits_any_set'`, `'bits_all_not_set'`, `'overlaps'`,
239+
`'neighbor'`, `'bits_all_set'`, `'bits_any_set'`, `'bits_all_not_set'` (in
240+
both lowercase/uppercase) instead of constants
266241

267242
_**Return Value**_
268243

@@ -274,19 +249,19 @@ request, or empty array, if nothing was found.
274249
#### Example
275250

276251
``` php
277-
/* Select everything from space 'test' */
252+
// Select everything from space 'test'
278253
$tnt->select("test");
279-
/* Selects from space 'test' by PK with id == 1*/
254+
// Selects from space 'test' by PK with id == 1
280255
$tnt->select("test", 1);
281-
/* The same as previous */
256+
// The same as previous
282257
$tnt->select("test", array(1));
283-
/* Selects from space 'test' by secondary key from index 'isec' and == {1, 'hello'} */
258+
// Selects from space 'test' by secondary key from index 'isec' and == {1, 'hello'}
284259
$tnt->select("test", array(1, "hello"), "isec");
285-
/* Selects second hundred of rows from space test */
260+
// Selects second hundred of rows from space test
286261
$tnt->select("test", null, null, 100, 100);
287-
/* Selects second hundred of rows from space test in reverse equality order */
288-
/* It meanse: select penultimate hundred */
289-
$tnt->select("test", null, null, 100, 100, TARANTOOL_ITER_REQ);
262+
// Selects second hundred of rows from space test in reverse equality order
263+
// It meanse: select penultimate hundred
264+
$tnt->select("test", null, null, 100, 100, Tarantool::ITERATOR_REQ);
290265
```
291266

292267
### Tarantool::insert, Tarantool::replace
@@ -312,12 +287,12 @@ _**Return Value**_
312287
#### Example
313288

314289
``` php
315-
/* It'll be processed OK, since no tuples with PK == 1 are in space 'test' */
290+
// It'll be processed OK, since no tuples with PK == 1 are in space 'test'
316291
$tnt->insert("test", array(1, 2, "smth"));
317-
/* We've just inserted tuple with PK == 1, so it'll fail */
318-
/* error will be ER_TUPLE_FOUND */
292+
// We've just inserted tuple with PK == 1, so it'll fail
293+
// error will be ER_TUPLE_FOUND
319294
$tnt->insert("test", array(1, 3, "smth completely different"));
320-
/* But it won't be a problem for replace */
295+
// But it won't be a problem for replace
321296
$tnt->replace("test", array(1, 3, "smth completely different"));
322297
```
323298

@@ -396,11 +371,11 @@ _**Return Value**_
396371
#### Example
397372

398373
``` php
399-
/* Following code will delete all tuples from space `test` */
374+
// Following code will delete all tuples from space `test`
400375
$tuples = $tnt->select("test");
401376
foreach($tuples as $value) {
402-
$tnt->delete("test", Array($value[0]));
403-
}
377+
$tnt->delete("test", array($value[0]));
378+
}
404379
```
405380

406381
### Tarantool::update
@@ -516,7 +491,7 @@ $tnt->update("test", 1, array(
516491
array(
517492
"field" => 4,
518493
"op" => "=",
519-
"arg" => intval(0x11111)
494+
"arg" => 0x11111,
520495
),
521496
));
522497
$tnt->update("test", 1, array(
@@ -528,21 +503,21 @@ $tnt->update("test", 1, array(
528503
array(
529504
"field" => 4,
530505
"op" => "&",
531-
"arg" => intval(0x10101)
506+
"arg" => 0x10101,
532507
)
533508
));
534509
$tnt->update("test", 1, array(
535510
array(
536511
"field" => 4,
537512
"op" => "^",
538-
"arg" => intval(0x11100)
513+
"arg" => 0x11100,
539514
)
540515
));
541516
$tnt->update("test", 1, array(
542517
array(
543518
"field" => 4,
544519
"op" => "|",
545-
"arg" => intval(0x00010)
520+
"arg" => 0x00010,
546521
)
547522
));
548523
$tnt->update("test", 1, array(
@@ -559,7 +534,7 @@ $tnt->update("test", 1, array(
559534
### Tarantool::upsert
560535

561536
``` php
562-
public array Tarantool::upsert(mixed $space, mixed $key, array $ops [, number $index] )
537+
public array Tarantool::upsert(mixed $space, array $tuple, array $ops [, number $index] )
563538
```
564539

565540
_**Description**_: Update or Insert command (If tuple with PK == PK('tuple') exists,
@@ -590,3 +565,10 @@ $tnt->upsert("test", array(124, 10, "new tuple"), array(
590565
)
591566
));
592567
```
568+
569+
570+
## Deprecated
571+
572+
* Global constants, e.g. `TARANTOOL_ITER_<name>`
573+
* `Tarantool::authenticate` method
574+
* configuration parameter: `tarantool.con_per_host`

config.m4

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ if test "$PHP_TARANTOOL" != "no"; then
77
src/tarantool.c \
88
src/tarantool_network.c \
99
src/tarantool_msgpack.c \
10-
src/tarantool_manager.c \
1110
src/tarantool_schema.c \
1211
src/tarantool_proto.c \
1312
src/tarantool_tp.c \
13+
src/tarantool_exception.c \
1414
src/third_party/msgpuck.c \
1515
src/third_party/sha1.c \
1616
src/third_party/base64_tp.c \

package.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
2626
<release>beta</release>
2727
<api>beta</api>
2828
</stability>
29-
<license uri="http://opensource.org/licenses/mit-license.php">MIT</license>
29+
<license uri="http://opensource.org/licenses/bsd-license.php">BSD 2-Clause</license>
3030
<notes>-</notes>
3131
<contents>
3232
<dir name="/">

rpm/php-tarantool.spec

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Version: 0.1.0.0
77
Release: 1%{?dist}
88
Summary: PECL PHP driver for Tarantool/Box
99
Group: Development/Languages
10-
License: MIT
10+
License: BSD 2-Clause
1111
URL: https://github.com/tarantool/tarantool-php/
1212
Source0: tarantool-php-%{version}.tar.gz
1313
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)

0 commit comments

Comments
 (0)