Code Monkey home page Code Monkey logo

tarantool-php's Introduction

PHP driver for Tarantool 1.6 ============================

PECL PHP driver for Tarantool.

If you're looking for 1.5 version, check out branch 'stable'.

Build

To build Tarantool PHP extenstion PHP-devel package is required. The package should contain phpize utility.

$ phpize
$ ./configure
$ make
$ make install

Test

To run tests Tarantool server and PHP/PECL package are requred.

$ ./test-run.py

It'll automaticly find and start Tarantool and, then, run phpunit.phar based tests. If Tarantool doesn't defined in PATH variable, you may define it in TARANTOOL_BOX_PATH enviroment variable.

$ TARANTOOL_BOX_PATH=/path/to/tarantool/bin/tarantool ./test-run.py

Installing from PEAR

Tarantool-PHP has its own PEAR repository. You may install it from PEAR with just a few commands:

pecl channel-discover tarantool.github.io/tarantool-php/pecl
pecl install Tarantool-PHP/Tarantool-beta

Building RPM/DEB/PECL Packages

For building packages - please, read README.PACK.md

IDE autocompletion

Stubs can be found at tarantool/tarantool-php-stubs. Place it into project library path in your IDE.

API and Configuration

Configuration file

  • tarantool.persistent - Enable persistent connections (don't close connections between sessions) (defaults: True, can't be changed in runtime)
  • tarantool.timeout - Connection timeout (defaults: 10 seconds, can be changed in runtime)
  • tarantool.retry_count - Amount of attempts to connect (defaults: 1, can be changed in runtime)
  • tarantool.retry_sleep - Sleep between connecting retries (defaults: 0.1 second, can be changed in runtime)
  • tarantool.request_timeout - Read/write timeout for requests (defaults: 10 second, can be changed in runtime)

Classes and Methods

Usage

  1. Predefined Constants
  2. Class Tarantool
  1. Manipulation connection
  1. Database queries

Predefined Constants

Description: Available Tarantool Constants

  • Tarantool::ITERATOR_EQ - Equality iterator (ALL)
  • Tarantool::ITERATOR_REQ - Reverse equality iterator
  • Tarantool::ITERATOR_ALL - Get all rows
  • Tarantool::ITERATOR_LT - Less then iterator
  • Tarantool::ITERATOR_LE - Less and equal iterator
  • Tarantool::ITERATOR_GE - Greater and equal iterator
  • Tarantool::ITERATOR_GT - Gtreater then iterator
  • Tarantool::ITERATOR_BITS_ALL_SET - check if all given bits are set (BITSET only)
  • Tarantool::ITERATOR_BITS_ANY_SET - check if any given bits are set (BITSET only)
  • Tarantool::ITERATOR_BITS_ALL_NOT_SET - check if all given bits are not set (BITSET only)
  • Tarantool::ITERATOR_OVERLAPS - find dots in the n-dimension cube (RTREE only)
  • Tarantool::ITERATOR_NEIGHBOR - find nearest dots (RTREE only)

Class Tarantool

Tarantool {
    public       Tarantool::__construct ( [ string $host = 'localhost' [, int $port = 3301 [, string $user = "guest" [, string $password = NULL [, string $persistent_id = NULL ] ] ] ] ] )
    public bool  Tarantool::connect ( void )
    public bool  Tarantool::disconnect ( void )
    public bool  Tarantool::flushSchema ( void )
    public bool  Tarantool::ping ( void )
    public array Tarantool::select (mixed $space [, mixed $key = array() [, mixed $index = 0 [, int $limit = PHP_INT_MAX [, int $offset = 0 [, $iterator = Tarantool::ITERATOR_EQ ] ] ] ] ] )
    public array Tarantool::insert (mixed $space, array $tuple)
    public array Tarantool::replace (mixed $space, array $tuple)
    public array Tarantool::call (string $procedure [, mixed args [, array $opts ] ] )
    public array Tarantool::evaluate (string $expression [, mixed args] )
    public array Tarantool::delete (mixed $space, mixed $key [, mixed $index] )
    public array Tarantool::update (mixed $space, mixed $key, array $ops [, number $index] )
    public array Tarantool::upsert (mixed $space, mixed $key, array $ops [, number $index] )
}

Tarantool::__construct

public Tarantool::__construct ( [ string $host = 'localhost' [, int $port = 3301 [, string $user = "guest" [, string $password = NULL [, string $persistent_id = NULL ] ] ] ] ] )

Description: Creates a Tarantool client

Parameters

  • host: string, default is 'localhost'
  • port: number, default is 3301
  • user: string, default is 'guest'
  • password: string
  • persistent_id: string (set it, and connection will be persistent, if persistent in config isn't set)

Return Value

Tarantool class instance

Example
$tnt = new Tarantool(); // -> new Tarantool('localhost', 3301);
$tnt = new Tarantool('tarantool.org'); // -> new Tarantool('tarantool.org', 3301);
$tnt = new Tarantool('localhost', 16847);

Manipulation connection

Tarantool::connect

public bool Tarantool::connect ( void )

Description: Explicit connect to Tarantool Server. If not used, then connection will be opened on demand.

Return Value

BOOL: True on success Raises Exception if can't connect to Tarantool.

Tarantool::disconnect

public bool Tarantool::disconnect ( void )

Description: Explicitly close connection to Tarantool Server. If you're using persistent connections, then it'll be saved to connection pool.

Return Value

BOOL: True

Tarantool::flushSchema

public bool Tarantool::flushSchema ( void )

Description: Remove space/index schema from client.

Return Value

BOOL: True

Tarantool::ping

public bool Tarantool::ping ( void )

Description: Ping Tarantool server.

Return Value

BOOL: True

Throws Exception on error.

Database queries

Tarantool::select

public array Tarantool::select(mixed $space [, mixed $key = array() [, mixed $index = 0 [, int $limit = PHP_INT_MAX [, int $offset = 0 [, $iterator = Tarantool::ITERATOR_EQ ] ] ] ] ] )

Description: Execute select query from Tarantool server.

Parameters

  • space: String/Number, Space id to select from (mandatory)
  • key: String/Number or Array, key to select (Array() by default, selects everything from space)
  • index: String/Number, Index id to select from (0 by default)
  • limit: Number, limit number of rows to return from select (INT_MAX by default)
  • offset: Number, offset to select from (0 by default)
  • iterator: Constant, iterator type. See Predefined Constants for more information (Tarantool::ITERATOR_EQ by default). You can also use strings 'eq', 'req', 'all', 'lt', 'le', 'ge', 'gt', 'bits_all_set', 'bits_any_set', 'bits_all_not_set', 'overlaps', 'neighbor', 'bits_all_set', 'bits_any_set', 'bits_all_not_set' (in both lowercase/uppercase) instead of constants

Return Value

Array of arrays: in case of success - list of tuples that satisfy your request, or empty array, if nothing was found.

BOOL: False and raises Exception in case of error.

Example

// Select everything from space 'test'
$tnt->select("test");
// Selects from space 'test' by PK with id == 1
$tnt->select("test", 1);
// The same as previous
$tnt->select("test", array(1));
// Selects from space 'test' by secondary key from index 'isec' and == {1, 'hello'}
$tnt->select("test", array(1, "hello"), "isec");
// Selects second hundred of rows from space test
$tnt->select("test", null, null, 100, 100);
// Selects second hundred of rows from space test in reverse equality order
// It meanse: select penultimate hundred
$tnt->select("test", null, null, 100, 100, Tarantool::ITERATOR_REQ);

Tarantool::insert, Tarantool::replace

public array Tarantool::insert(mixed $space, array $tuple)
public array Tarantool::replace(mixed $space, array $tuple)

Description: Insert (if not exists query with same PK) or Replace tuple.

Parameters

  • space: String/Number, Space id to select from (mandatory)
  • tuple: Array, Tuple to Insert/Replace (mandatory)

Return Value

Array in case of success - tuple that was inserted into Tarantool.

BOOL: False and raises Exception in case of error.

Example

// It'll be processed OK, since no tuples with PK == 1 are in space 'test'
$tnt->insert("test", array(1, 2, "smth"));
// We've just inserted tuple with PK == 1, so it'll fail
// error will be ER_TUPLE_FOUND
$tnt->insert("test", array(1, 3, "smth completely different"));
// But it won't be a problem for replace
$tnt->replace("test", array(1, 3, "smth completely different"));

Tarantool::call

public array Tarantool::call(string $procedure [, mixed args [, array $opts]])

Description: Call stored procedure

Parameters

  • procedure: String, procedure to call (mandatory)
  • args: Any value to pass to procedure as arguments (empty by default)
  • opts: Array, options

Options

  • call_16
    If true - call_16 mode of "call" will be used (returned data converted to tuples).
    If false - call_17 mode of "call" will be used (returned data has an arbitrary structure). Since tarantool 1.7.2.
    Default - call_16 mode.
    array(
      "call_16" => <bool>
    ),
    

Return Value

BOOL: False and raises Exception in case of error.

call_16 mode (default):

Array of arrays in case of success - tuples that were returned by stored procedure.

call_17 mode:

Any value, that was returned by stored procedure.

Example

$tnt->call("test_2");
$tnt->call("test_3", array(3, 4), array('call_16' => false));

Tarantool::evaluate

public array Tarantool::evaluate(string $expression [, mixed args])

Description: Evaluate given lua code (demands current user to have 'execute' rights for 'universe' in Tarantool)

Parameters

  • expression: String, Lua code to evaluate (mandatory)
  • args: Any value to pass to procedure as arguments (empty by default)

Return Value

Any value, that was returned from evaluated code.

BOOL: False and raises Exception in case of error.

Example

$tnt->eval("return test_2()");
$tnt->eval("return test_3(...)", array(3, 4));
$tnt->evaluate("return test_3(...)", array(3, 4));

Tarantool::delete

public array Tarantool::delete(mixed $space, mixed $key [, mixed $index])

Description: Delete record with given key.

Parameters

  • space: String/Number, Space id to delete from (mandatory)
  • key: String/Number or Array, key to delete row with (mandatory)
  • index: String/Number, Index id to delete from (0 by default)

Return Value

Array in case of success - tuple that was deleted by query.

BOOL: False and raises Exception in case of error.

Example

// Following code will delete all tuples from space `test`
$tuples = $tnt->select("test");
foreach($tuples as $value) {
    $tnt->delete("test", array($value[0]));
}

Tarantool::update

public array Tarantool::update(mixed $space, mixed $key, array $ops [, number $index] )

Description: Update record with given key (update in Tarantool is apply multiple given operations to tuple)

Parameters

  • space: String/Number, Space id to select from (mandatory)
  • key: Array/Scalar, Key to match tuple with (mandatory)
  • ops: Array of Arrays, Operations to execute if tuple was found

Operations

<serializable> - any simple type which converts to MsgPack (scalar/array).

  • Splice operation - take field'th field, replace length bytes from offset byte with 'list':
    array(
      "field" => <number>,
      "op"    => ":",
      "offset"=> <number>,
      "length"=> <number>,
      "list"  => <string>
    ),
    
  • Numeric operations:
    array(
      "field" => <number>,
      "op" => ("+"|"-"|"&"|"^"|"|"),
      "arg" => <number>
    ),
    
    • "+" for addition
    • "-" for substraction
    • "&" for bitwise AND
    • "^" for bitwise XOR
    • "|" for bitwise OR
  • Delete arg fields from 'field':
    array(
      "field" => <number>,
      "op" => "#",
      "arg" => <number>
    )
    
  • Replace/Insert before operations:
    array(
      "field" => <number>,
      "op"    => ("="|"!"),
      "arg"   => <serializable>
    )
    
    • "=" replace field'th field with 'arg'
    • "=" insert 'arg' before field'th field
array(
  array(
    "field" => <number>,
    "op"    => ":",
    "offset"=> <number>,
    "length"=> <number>,
    "list"  => <string>
  ),
  array(
    "field" => <number>,
    "op" => ("+"|"-"|"&"|"^"|"|"),
    "arg" => <number>
  ),
  array(
    "field" => <number>,
    "op" => "#",
    "arg" => <number>
  ),
  array(
    "field" => <number>,
    "op"    => ("="|"!"),
    "arg"   => <serializable>
  )
)

Return Value

Array in case of success - tuple after it was updated.

BOOL: False and raises Exception in case of error.

Example

$tnt->update("test", 1, array(
  array(
    "field" => 1,
    "op" => "+",
    "arg" => 16
  ),
  array(
    "field" => 3,
    "op" => "=",
    "arg" => 98
  ),
  array(
    "field" => 4,
    "op" => "=",
    "arg" => 0x11111,
  ),
));
$tnt->update("test", 1, array(
  array(
    "field" => 3,
    "op" => "-",
    "arg" => 10
  ),
  array(
    "field" => 4,
    "op" => "&",
    "arg" => 0x10101,
  )
));
$tnt->update("test", 1, array(
  array(
    "field" => 4,
    "op" => "^",
    "arg" => 0x11100,
  )
));
$tnt->update("test", 1, array(
  array(
    "field" => 4,
    "op" => "|",
    "arg" => 0x00010,
  )
));
$tnt->update("test", 1, array(
  array(
    "field" => 2,
    "op" => ":",
    "offset" => 2,
    "length" => 2,
    "list" => "rrance and phillipe show"
  )
));

Tarantool::upsert

public array Tarantool::upsert(mixed $space, array $tuple, array $ops [, number $index] )

Description: Update or Insert command (If tuple with PK == PK('tuple') exists, then it'll update this tuple with 'ops', otherwise 'tuple' will be inserted)

Parameters

  • space: String/Number, Space id to select from (mandatory)
  • tuple: Array, Tuple to Insert (mandatory)
  • ops: Array of Arrays, Operations to execute if tuple was found. Operations are described in update section.

Return Value

Nothing. In simple cases - it mustn't throw errors and returns nothing, but sometimes it'll, check out documentation

BOOL: False and raises Exception in case of error.

Example

$tnt->upsert("test", array(124, 10, "new tuple"), array(
  array(
    "field" => 1,
    "op" => "+",
    "arg" => 10
  )
));

Deprecated

  • Global constants, e.g. TARANTOOL_ITER_<name>
  • Tarantool::authenticate method
  • configuration parameter: tarantool.con_per_host

tarantool-php's People

Contributors

alexmasterov avatar alg1973 avatar amdrozdov avatar bendalton avatar bigbes avatar ekho avatar kostja avatar leonidvas avatar mikhainin avatar remicollet avatar rtsisyk avatar rybakit avatar sannis avatar stefansaraev avatar tony2001 avatar totktonada avatar unera avatar yolkov avatar zlobspb avatar zloidemon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tarantool-php's Issues

Error while 'make install'

Hi! I have Ubuntu 12.04 and PHP 5.3.10-1ubuntu3.13 (fpm-fcgi)
Trying to build php-connector. Got theese warnings and errors:

root@kurtecka:/usr/src/tarantool-php# make install

/bin/bash /usr/src/tarantool-php/libtool --mode=compile cc  -I. -I/usr/src/tarantool-php -DPHP_ATOM_INC -I/usr/src/tarantool-php/include -I/usr/src/tarantool-php/main -I/usr/src/tarantool-php -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -I/src/third_party  -DHAVE_CONFIG_H  -g -O2   -c /usr/src/tarantool-php/src/tarantool_msgpack.c -o src/tarantool_msgpack.lo
libtool: compile:  cc -I. -I/usr/src/tarantool-php -DPHP_ATOM_INC -I/usr/src/tarantool-php/include -I/usr/src/tarantool-php/main -I/usr/src/tarantool-php -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -I/src/third_party -DHAVE_CONFIG_H -g -O2 -c /usr/src/tarantool-php/src/tarantool_msgpack.c  -fPIC -DPIC -o src/.libs/tarantool_msgpack.o
In file included from /usr/src/tarantool-php/src/tarantool_msgpack.c:4:0:
/usr/src/tarantool-php/src/php_tarantool.h:32:1: warning: data definition has no type or storage class [enabled by default]
/usr/src/tarantool-php/src/php_tarantool.h:32:1: warning: parameter names (without types) in function declaration [enabled by default]
/usr/src/tarantool-php/src/php_tarantool.h:33:1: warning: data definition has no type or storage class [enabled by default]
/usr/src/tarantool-php/src/php_tarantool.h:33:1: warning: parameter names (without types) in function declaration [enabled by default]
/usr/src/tarantool-php/src/php_tarantool.h:34:1: warning: data definition has no type or storage class [enabled by default]
/usr/src/tarantool-php/src/php_tarantool.h:34:1: warning: parameter names (without types) in function declaration [enabled by default]
/usr/src/tarantool-php/src/php_tarantool.h:36:1: warning: data definition has no type or storage class [enabled by default]
/usr/src/tarantool-php/src/php_tarantool.h:36:1: warning: parameter names (without types) in function declaration [enabled by default]
/usr/src/tarantool-php/src/php_tarantool.h:37:1: warning: data definition has no type or storage class [enabled by default]
/usr/src/tarantool-php/src/php_tarantool.h:37:1: warning: parameter names (without types) in function declaration [enabled by default]
/usr/src/tarantool-php/src/php_tarantool.h:38:1: warning: data definition has no type or storage class [enabled by default]
/usr/src/tarantool-php/src/php_tarantool.h:38:1: warning: parameter names (without types) in function declaration [enabled by default]
/usr/src/tarantool-php/src/php_tarantool.h:39:1: warning: data definition has no type or storage class [enabled by default]
/usr/src/tarantool-php/src/php_tarantool.h:39:1: warning: parameter names (without types) in function declaration [enabled by default]
/usr/src/tarantool-php/src/php_tarantool.h:40:1: warning: data definition has no type or storage class [enabled by default]
/usr/src/tarantool-php/src/php_tarantool.h:40:1: warning: parameter names (without types) in function declaration [enabled by default]
/usr/src/tarantool-php/src/php_tarantool.h:41:1: warning: data definition has no type or storage class [enabled by default]
/usr/src/tarantool-php/src/php_tarantool.h:41:1: warning: parameter names (without types) in function declaration [enabled by default]
/usr/src/tarantool-php/src/php_tarantool.h:42:1: warning: data definition has no type or storage class [enabled by default]
/usr/src/tarantool-php/src/php_tarantool.h:42:1: warning: parameter names (without types) in function declaration [enabled by default]
/usr/src/tarantool-php/src/php_tarantool.h:43:1: warning: data definition has no type or storage class [enabled by default]
/usr/src/tarantool-php/src/php_tarantool.h:43:1: warning: parameter names (without types) in function declaration [enabled by default]
/usr/src/tarantool-php/src/php_tarantool.h:44:1: warning: data definition has no type or storage class [enabled by default]
/usr/src/tarantool-php/src/php_tarantool.h:44:1: warning: parameter names (without types) in function declaration [enabled by default]
/usr/src/tarantool-php/src/php_tarantool.h:45:1: warning: data definition has no type or storage class [enabled by default]
/usr/src/tarantool-php/src/php_tarantool.h:45:1: warning: parameter names (without types) in function declaration [enabled by default]
/usr/src/tarantool-php/src/php_tarantool.h:46:1: warning: data definition has no type or storage class [enabled by default]
/usr/src/tarantool-php/src/php_tarantool.h:46:1: warning: parameter names (without types) in function declaration [enabled by default]
/usr/src/tarantool-php/src/tarantool_msgpack.c: In function 'php_mp_pack_hash_recursively':
/usr/src/tarantool-php/src/tarantool_msgpack.c:150:19: error: 'HASH_KEY_NON_EXISTENT' undeclared (first use in this function)
/usr/src/tarantool-php/src/tarantool_msgpack.c:150:19: note: each undeclared identifier is reported only once for each function it appears in
/usr/src/tarantool-php/src/tarantool_msgpack.c: In function 'php_mp_unpack_bool':
/usr/src/tarantool-php/src/tarantool_msgpack.c:257:2: error: 'else' without a previous 'if'
/usr/src/tarantool-php/src/tarantool_msgpack.c: In function 'php_mp_sizeof_hash_recursively':
/usr/src/tarantool-php/src/tarantool_msgpack.c:433:19: error: 'HASH_KEY_NON_EXISTENT' undeclared (first use in this function)
make: *** [src/tarantool_msgpack.lo] Error 1

ER_INVALID_MSGPACK: Invalid MsgPack - packet body

Установил tarantool, tarantool php на centos 6.6
Запускаю tarantool example.lua

box.cfg{listen=3391}
example = box.space.example
if not example then
    example = box.schema.space.create('example')
    box.space.example:create_index("primary", {type = 'hash', parts = {1, 'STR'}})
end

при выполнении тестового php кода:

<?
$tarantool = new Tarantool('localhost', '3391');
$tarantool->connect();
var_export($tarantool->select('example', 'example_key'));
return;
?>

Выходит ошибка ER_INVALID_MSGPACK: Invalid MsgPack - packet body
2015-04-21_22-34-22

Как ее побороть?

Make `admin` method like `call`

С удивлением обнаружил, что метод admin возвращает в ответ чистый текст, а не распаршенную структуру, как call. Имхо, было бы хорошо это унифицировать.

Uncaught exception 'Exception' with message 'failed to connect: Cannot assign requested address

Sometimes i've got this:
PHP Fatal error: Uncaught exception 'Exception' with message 'failed to connect: Cannot assign requested address' in /root/script.php:75
Stack trace:
#0 /root/script.php(75): Tarantool->select(4, 0, 464008538842)
#1 {main}

thrown in /root/script.php on line 75

statistics:
  REPLACE:    { rps:  0    , total:  889626      }
  SELECT:     { rps:  259  , total:  12847488    }
  UPDATE:     { rps:  0    , total:  0           }
  DELETE_1_3: { rps:  0    , total:  0           }
  DELETE:     { rps:  0    , total:  2           }
  CALL:       { rps:  0    , total:  0           }

ulimit -n
16384

Please help.

Persistent connection

It would be great to add persistent connection ability to extension. Create new connection for every request is too expensive.

Thanks in advance.

Segmentation fault while mocking with PHPUnit

// FooTest.php

class FooTest extends \PHPUnit_Framework_TestCase
{
    public function testFoo()
    {
        $tnt = $this->getMock('Tarantool');
        $tnt->expects($this->once())->method('ping');
        $tnt->ping();
    }
}
$ phpunit FooTest.php
PHPUnit 4.6.4 by Sebastian Bergmann and contributors.

Segmentation fault

Unable to build tarantool extension as static

Put the sources into ext/tarantool, run ./buildconf, then ./configure --enable-tarantool (that's the correct option for extensions not linking against any libs), see lots of errors.

Rename the debian package to php5-tarantool

I've seen your package in the debian NEW queue 1.

The binary package doesn't follow the naming convention: it should be named php5-tarantoll. Also, we usually name the source package php-tarantool.

Some more remarks:

null result

Ubuntu 12.04, php 5.5 (fpm)

Well, I have this code:

$tnt = new Tarantool('localhost', 3301);
//$tnt->connect();
//$tnt->authenticate('user', 'pass');
$replace_result = $tnt->replace('tester', array(5, "ResStone", time().rand()));
$select_result = $tnt->select('tester', 5, 0);

echo 'result: '.json_encode($select_result);

Ok, result is always this:
'result: [[5,"ResStone","currentTime+random number"]]'

But if I comment 4th line of code ("replace"), then update the code and hit F5 in my browser window I'll get this result:
'result: [null] '

If I insert some tuple in 'tester'-space ( array(6, "ResWood", 666), for example ) from console-client, then press F5 to run this script

$tnt = new Tarantool('localhost', 3301);
$select_result = $tnt->select('tester', 6, 0);

echo 'result: '.json_encode($select_result);

tnen I'll get this result:
'result: [[5,"ResWood",666]] '

But! If I run this script once more, I'll get null-result.

It seems like I can get some tuples only after they was inserted/replaced, but not another time.

I tried to call Tarantool::connect() function (it is commented in my first example) before this operations. Nothing. I tried to grant user privilegies to read, write and execute to 'guest' and to new user (and authenticate from this new user). Same result too.

soft automatic schema reload

Now that the iproto protocol has sc_schema_id, fix the driver to perform "soft" schema reload.

  • load the current schema automatically when connection is established
  • include sc_schema_id in queries
  • if the response is ER_SCHEMA_CHANGED, reload the schema and re-issue the query.

tarantool/tarantool#1183

tarantool-php segfault

stacktrace:

    Program terminated with signal 11, Segmentation fault.
    #0  0x00007fcf8612b57f in __strlen_sse42 () from /lib64/libc.so.6
    Missing separate debuginfos, use: debuginfo-install httpd-2.2.15-39.el6.centos.x86_64

    (gdb) bt
    #0  0x00007fcf8612b57f in __strlen_sse42 () from /lib64/libc.so.6
    #1  0x00007fcf8105e1c8 in php_stream_from_persistent_id (persistent_id=0x0, stream=0x7fcf884c9a80) at /usr/local/src/php-5.5.20/main/streams/streams.c:121
    #2  0x00007fcf76c1993d in __tarantool_connect (obj=0x7fcf884c9a40, id=<value optimized out>) at /usr/local/src/tarantool-php/src/tarantool.c:222
    #3  0x00007fcf76c1a95d in zim_tarantool_class_insert (ht=<value optimized out>, return_value=0x7fcf87a9a2b8, return_value_ptr=<value optimized out>, this_ptr=<value optimized out>,
        return_value_used=<value optimized out>) at /usr/local/src/tarantool-php/src/tarantool.c:953
    #4  0x00007fcf81126c73 in zend_do_fcall_common_helper_SPEC (execute_data=<value optimized out>) at /usr/local/src/php-5.5.20/Zend/zend_vm_execute.h:550
    #5  0x00007fcf811184f0 in execute_ex (execute_data=0x7fcf87a650a0) at /usr/local/src/php-5.5.20/Zend/zend_vm_execute.h:363
    #6  0x00007fcf810a41f9 in zend_execute_scripts (type=8, retval=0x0, file_count=3) at /usr/local/src/php-5.5.20/Zend/zend.c:1330
    #7  0x00007fcf81045c79 in php_execute_script (primary_file=0x7fff70eb8cf0) at /usr/local/src/php-5.5.20/main/main.c:2506
    #8  0x00007fcf811546b5 in php_handler (r=0x7fcf884a5c48) at /usr/local/src/php-5.5.20/sapi/apache2handler/sapi_apache2.c:667
    #9  0x00007fcf87ae8cd0 in ap_run_handler ()
    #10 0x00007fcf87aec58e in ap_invoke_handler ()
    #11 0x00007fcf87af7c50 in ap_process_request ()
    #12 0x00007fcf87af4ac8 in ?? ()
    #13 0x00007fcf87af07d8 in ap_run_process_connection ()
    #14 0x00007fcf87afcad7 in ?? ()
    #15 0x00007fcf87afcdea in ?? ()
    #16 0x00007fcf87afda6c in ap_mpm_run ()
    #17 0x00007fcf87ad49b0 in main ()
    (gdb) frame 1
    #1  0x00007fcf8105e1c8 in php_stream_from_persistent_id (persistent_id=0x0, stream=0x7fcf884c9a80) at /usr/local/src/php-5.5.20/main/streams/streams.c:121
    121        if (zend_hash_find(&EG(persistent_list), (char*)persistent_id, strlen(persistent_id)+1, (void*) &le) == SUCCESS) {
    (gdb) print (char *) persistent_id
    $6 = 0x0

    (gdb) frame 2
    #2  0x00007fcf76c1993d in __tarantool_connect (obj=0x7fcf884c9a40, id=<value optimized out>) at /usr/local/src/tarantool-php/src/tarantool.c:222
    222            php_stream_from_persistent_id(obj->persistent_id, &obj->stream TSRMLS_CC);

    (gdb) ptype obj
    type = struct tarantool_object {
        zend_object zo;
        char *host;
        int port;
        char *login;
        char *passwd;
        php_stream *stream;
        char *persistent_id;
        smart_str *value;
        struct tp *tps;
        char auth;
        char *greeting;
        char *salt;
        struct tarantool_schema *schema;
    } *
    (gdb) print (char *)obj.host
    $1 = 0x7fcf8877cc10 "corund.sv"
    (gdb) print obj.port
    $2 = 3301
    (gdb) print (char *)obj.login
    $3 = 0x0
    (gdb) print (char *)obj.passwd
    $4 = 0x0
    (gdb) print (char *)obj.persistent_id
    $5 = 0x0
    (gdb) print obj.auth
    $6 = 0 '\000'
    (gdb) print (char *)obj.greeting
    $7 = 0x7fcf884bcbb0 ""
    (gdb) print (char *)obj.salt
    $8 = 0x7fcf884bcbf0 ""

php:

    <?php
    $host = 'corund.sv';
    $space = 'segf';
    try {
      $tarantool = new Tarantool($host, 3301);
      $defaultData = array(
        1,
        2,
        'str_data',
        'str_data',
        3,
        'str_data',
        'str_data',
        'str_data',
        'str_data',
        'str_data',
        'str_data',
        'str_data',
        'str_data',
        'str_data',
        'str_data',
        'str_data',
        'str_data',
        'str_data',
        'str_data',
        0,
        1,
        2,
        3,
        4,
        5,
        6,
        7,
        8,
        9,
        10,
        'str_data',
        'str_data',
        0,
        'str_data',
        array('key' => 'value'),
        array('value'),
        'str_data',
        'str_data',
        'str_data',
        'str_data',
        'str_data',
        'str_data',
        'str_data',
        'str_data',
        'str_data',
        'str_data',
      );
      $tarantool->insert($space, $defaultData);
    } catch (Exception $e) {
      echo $e->getMessage();
    }
    die('<br>END');
    ?>

lua:

    #!/usr/bin/env tarantool
    box.cfg{
      listen = '3301',
    }
    segf = box.space.segf
    if not box.space.segf then
      box.schema.user.grant('guest','read,write,execute','universe')
      segf = box.schema.create_space('segf')
      segf:create_index('primary', {parts = {1, 'NUM'}})
    end

INI options are set to INI_ALL, but cannot be changed in runtime

Most of the INI options (5 out of 6) used in the extension are used only once - during the extension initialisation in MINIT(). This makes it impossible to change them in runtime, despite them all being PHP_INI_ALL.
Yes, ini_set() works fine and the value is being changed, no, this value isn't used anywhere.

Here's a simple way to fix it:

@@ -106,11 +107,11 @@ zend_module_entry tarantool_module_entry = {

 PHP_INI_BEGIN()
        PHP_INI_ENTRY("tarantool.timeout"     , "10.0", PHP_INI_ALL, NULL)
-       PHP_INI_ENTRY("tarantool.retry_count" , "1"   , PHP_INI_ALL, NULL)
-       PHP_INI_ENTRY("tarantool.retry_sleep" , "0.1" , PHP_INI_ALL, NULL)
-       PHP_INI_ENTRY("tarantool.persistent"  , "1"   , PHP_INI_ALL, NULL)
-       PHP_INI_ENTRY("tarantool.deauthorize" , "0"   , PHP_INI_ALL, NULL)
        PHP_INI_ENTRY("tarantool.con_per_host", "5"   , PHP_INI_ALL, NULL)
+       STD_PHP_INI_ENTRY("tarantool.retry_count" , "1"   , PHP_INI_ALL, OnUpdateLong, retry_count, zend_tarantool_globals, tarantool_globals)
+       STD_PHP_INI_ENTRY("tarantool.retry_sleep" , "0.1" , PHP_INI_ALL, OnUpdateReal, retry_sleep, zend_tarantool_globals, tarantool_globals)
+       STD_PHP_INI_ENTRY("tarantool.persistent"  , "0"   , PHP_INI_ALL, OnUpdateBool, persistent, zend_tarantool_globals, tarantool_globals)
+       STD_PHP_INI_ENTRY("tarantool.deauthorize" , "0"   , PHP_INI_ALL, OnUpdateBool, deauthorize, zend_tarantool_globals, tarantool_globals)
 PHP_INI_END()

 #ifdef COMPILE_DL_TARANTOOL

Cannot run tests

Successfully complete "make install" process after updating from php 5.3 to 5.5 (some errors mentioned in #15 still was there before update (I didn't copy them before updating unfortunately, but I'll try to reproduce them)).

Now when I try to "make test" I've got this error:

ERROR: Cannot run tests without CLI sapi.

Is it my fault (broken php or/and php CLI installation) or some problems in tarantool-php code?

Segmentation fault on unresolved hostname

Code

<?php
ini_set('display_errors', 'On');
try {
        $tnt = new Tarantool('random.host', 34111);
        $tnt->call('random', array());
} catch(Exception $e) {
        echo $e;
}

Output

Warning: Tarantool::call(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /xxx/test.php on line 5
Segmentation fault
$ php -v
PHP 5.4.23-pl0-gentoo (cli) (built: Feb  7 2014 15:58:15)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies

$ uname -a
Linux hostname 3.2.48-gentoo #1 SMP Tue Nov 5 14:25:48 MSK 2013 x86_64 Intel(R) Xeon(R) CPU E5-2620 0 @ 2.00GHz GenuineIntel GNU/Linux

An exception is thrown while creating a tube

$t = new \Tarantool();
$t->authenticate('tester', 'tester');
$t->call('queue.create_tube', ['foo', 'fifo']);

Output:

PHP Fatal error:  Uncaught exception 'Exception' with message 'Query error 32: 
unsupported Lua type 'function'' in ...

The tube is created though.

Segmentation fault with underscore in space name

Linux Mint 17.1 Rebecca x64

PHP 5.6.7-1+deb.sury.org~trusty+1 (cli) (built: Mar 24 2015 11:21:10) 
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies
    with Zend OPcache v7.0.4-dev, Copyright (c) 1999-2015, by Zend Technologies
    with Xdebug v2.2.5, Copyright (c) 2002-2014, by Derick Rethans

Latest extension compiled from source.

Runnig tarantool example.lua

example.lua is:

box.cfg{listen=3301}
example = box.space.example
if not example then
    example = box.schema.space.create('example')
    box.space.example:create_index("primary", {type = 'hash', parts = {1, 'STR'}})
end
box.schema.user.grant('guest', 'read,write,execute', 'universe')

Running php built-in server php -S localhost:8000 -t .

open in browser http://localhost:8000/example.php

example.php is:

$tarantool = new Tarantool('localhost', '3301');
$tarantool->connect();
var_export($tarantool->select('example_space', 'example_key'));

Browser says 'Connction refused', php built-in server ends with message 'Segmentation fault'

Select never finds if used not primary key

I have such space

localhost:3301> s

---
- index:
    0: &0
      unique: true
      parts:
      - type: NUM
        fieldno: 1
      id: 0
      space_id: 514
      name: primary
      type: HASH
    1: &1
      unique: false
      parts:
      - type: NUM
        fieldno: 3
      id: 1
      space_id: 514
      name: secondary
      type: TREE
    primary: *0
    secondary: *1
  on_replace: 'function: 0xb6e432a0'
  temporary: false
  id: 514
  engine: memtx
  enabled: true
  name: tester
  field_count: 0

I have script ( i want find all rows less 10):

<?php
$tarantool = new Tarantool("localhost", 3301);
for ($i = 0; $i < 1000; $i++)
{
    $tarantool->insert("tester", array($i, uniqid(), $i));
}

$row = $tarantool->select('tester', 10);
$rows = $tarantool->select('tester', 10, 'secondary', null, null, 3);

// ITER_LT = 3

Variable $rows is always empty array.

PHP 5.5.9-1ubuntu4.14

support session handler API

Support integration with expirationd and store sessions via php session handler API in expirationd space.

Build error

On Ubuntu 14.04

user@server:/tmp/p/tarantool-php-master# make
/bin/bash /tmp/p/tarantool-php-master/libtool --mode=compile cc  -I. -I/tmp/p/tarantool-php-master -DPHP_ATOM_INC -I/tmp/p/tarantool-php-master/include -I/tmp/p/tarantool-php-master/main -I/tmp/p/tarantool-php-master -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -I/src/third_party  -DHAVE_CONFIG_H  -g -O2   -c /tmp/p/tarantool-php-master/src/tarantool.c -o src/tarantool.lo 
libtool: compile:  cc -I. -I/tmp/p/tarantool-php-master -DPHP_ATOM_INC -I/tmp/p/tarantool-php-master/include -I/tmp/p/tarantool-php-master/main -I/tmp/p/tarantool-php-master -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -I/src/third_party -DHAVE_CONFIG_H -g -O2 -c /tmp/p/tarantool-php-master/src/tarantool.c  -fPIC -DPIC -o src/.libs/tarantool.o
/tmp/p/tarantool-php-master/src/tarantool.c: In function 'get_spaceno_by_name':
/tmp/p/tarantool-php-master/src/tarantool.c:677:2: warning: passing argument 2 of 'call_user_function' from incompatible pointer type [enabled by default]
  call_user_function(NULL, &obj, fname, retval, 4, args TSRMLS_CC);
  ^
In file included from /usr/include/php5/main/php.h:39:0,
                 from /tmp/p/tarantool-php-master/src/tarantool.c:7:
/usr/include/php5/Zend/zend_API.h:450:14: note: expected 'struct zval **' but argument is of type 'struct tarantool_object **'
 ZEND_API int call_user_function(HashTable *function_table, zval **object_pp, zval *function_name, zval *retval_ptr, zend_uint param_count, zval *params[] TSRMLS_DC);
              ^
/tmp/p/tarantool-php-master/src/tarantool.c: In function 'get_indexno_by_name':
/tmp/p/tarantool-php-master/src/tarantool.c:736:2: warning: passing argument 2 of 'call_user_function' from incompatible pointer type [enabled by default]
  call_user_function(NULL, &obj, fname, retval, 4, args TSRMLS_CC);
  ^
In file included from /usr/include/php5/main/php.h:39:0,
                 from /tmp/p/tarantool-php-master/src/tarantool.c:7:
/usr/include/php5/Zend/zend_API.h:450:14: note: expected 'struct zval **' but argument is of type 'struct tarantool_object **'
 ZEND_API int call_user_function(HashTable *function_table, zval **object_pp, zval *function_name, zval *retval_ptr, zend_uint param_count, zval *params[] TSRMLS_DC);
              ^
In file included from /tmp/p/tarantool-php-master/src/tarantool.c:19:0:
/tmp/p/tarantool-php-master/src/tarantool.c: In function 'php_tarantool_init_globals':
/tmp/p/tarantool-php-master/src/php_tarantool.h:85:44: error: request for member 'sync_counter' in something not a structure or union
 #  define TARANTOOL_G(v) (tarantool_globals.v)
                                            ^
/tmp/p/tarantool-php-master/src/tarantool.c:784:2: note: in expansion of macro 'TARANTOOL_G'
  TARANTOOL_G(sync_counter) = 0;
  ^
/tmp/p/tarantool-php-master/src/php_tarantool.h:85:44: error: request for member 'retry_count' in something not a structure or union
 #  define TARANTOOL_G(v) (tarantool_globals.v)
                                            ^
/tmp/p/tarantool-php-master/src/tarantool.c:785:2: note: in expansion of macro 'TARANTOOL_G'
  TARANTOOL_G(retry_count)  = INI_INT("tarantool.retry_count");
  ^
/tmp/p/tarantool-php-master/src/php_tarantool.h:85:44: error: request for member 'retry_sleep' in something not a structure or union
 #  define TARANTOOL_G(v) (tarantool_globals.v)
                                            ^
/tmp/p/tarantool-php-master/src/tarantool.c:786:2: note: in expansion of macro 'TARANTOOL_G'
  TARANTOOL_G(retry_sleep)  = INI_FLT("tarantool.retry_sleep");
  ^
/tmp/p/tarantool-php-master/src/php_tarantool.h:85:44: error: request for member 'deauthorize' in something not a structure or union
 #  define TARANTOOL_G(v) (tarantool_globals.v)
                                            ^
/tmp/p/tarantool-php-master/src/tarantool.c:790:2: note: in expansion of macro 'TARANTOOL_G'
  TARANTOOL_G(deauthorize) = deauthorize;
  ^
/tmp/p/tarantool-php-master/src/php_tarantool.h:85:44: error: request for member 'manager' in something not a structure or union
 #  define TARANTOOL_G(v) (tarantool_globals.v)
                                            ^
/tmp/p/tarantool-php-master/src/tarantool.c:791:2: note: in expansion of macro 'TARANTOOL_G'
  TARANTOOL_G(manager) = pool_manager_create(persistent, con_per_host, deauthorize);
  ^
make: *** [src/tarantool.lo] Error 1

Ubuntu 12.04

user@server2:/tmp/p/tarantool-php-master# make
/bin/sh /tmp/p/tarantool-php-master/libtool --mode=compile cc  -I. -I/tmp/p/tarantool-php-master -DPHP_ATOM_INC -I/tmp/p/tarantool-php-master/include -I/tmp/p/tarantool-php-master/main -I/tmp/p/tarantool-php-master -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -I/src/third_party  -DHAVE_CONFIG_H  -g -O2   -c /tmp/p/tarantool-php-master/src/tarantool.c -o src/tarantool.lo 
libtool: compile:  cc -I. -I/tmp/p/tarantool-php-master -DPHP_ATOM_INC -I/tmp/p/tarantool-php-master/include -I/tmp/p/tarantool-php-master/main -I/tmp/p/tarantool-php-master -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -I/src/third_party -DHAVE_CONFIG_H -g -O2 -c /tmp/p/tarantool-php-master/src/tarantool.c  -fPIC -DPIC -o src/.libs/tarantool.o
/tmp/p/tarantool-php-master/src/tarantool.c: In function 'get_spaceno_by_name':
/tmp/p/tarantool-php-master/src/tarantool.c:677:2: warning: passing argument 2 of 'call_user_function' from incompatible pointer type [enabled by default]
/usr/include/php5/Zend/zend_API.h:429:14: note: expected 'struct zval **' but argument is of type 'struct tarantool_object **'
/tmp/p/tarantool-php-master/src/tarantool.c: In function 'get_indexno_by_name':
/tmp/p/tarantool-php-master/src/tarantool.c:736:2: warning: passing argument 2 of 'call_user_function' from incompatible pointer type [enabled by default]
/usr/include/php5/Zend/zend_API.h:429:14: note: expected 'struct zval **' but argument is of type 'struct tarantool_object **'
/tmp/p/tarantool-php-master/src/tarantool.c: In function 'php_tarantool_init_globals':
/tmp/p/tarantool-php-master/src/tarantool.c:784:2: error: request for member 'sync_counter' in something not a structure or union
/tmp/p/tarantool-php-master/src/tarantool.c:785:2: error: request for member 'retry_count' in something not a structure or union
/tmp/p/tarantool-php-master/src/tarantool.c:786:2: error: request for member 'retry_sleep' in something not a structure or union
/tmp/p/tarantool-php-master/src/tarantool.c:790:2: error: request for member 'deauthorize' in something not a structure or union
/tmp/p/tarantool-php-master/src/tarantool.c:791:2: error: request for member 'manager' in something not a structure or union
make: *** [src/tarantool.lo] Error 1

Incorrect request code php_tp_sizeof_ping()

The current code in php_tp_sizeof_ping():

size_t php_tp_sizeof_ping(uint32_t sync) {
    return php_tp_sizeof_header(TNT_AUTH, sync);
}

I believe it should be TNT_PING instead of TNT_AUTH. It doesn't make any difference with the current protocol constants, but is something I came across while reading the code.

Query error 22: Tuple/Key must be MsgPack array

When I'm calling Tarantool function which decodes MsgPack data using PHP extension, I'm getting following error: 'Query error 22: Tuple/Key must be MsgPack array'.

Lua script:

box.cfg{
    listen = 3301
}
box.schema.user.grant('guest','read,write,execute','universe')

msgpack = require('msgpack')
if box.space.test == nil then
    box.schema.create_space('test')
    box.space.test:create_index('primary', {parts = {1, 'NUM'}})
end

t = box.space.test
t:truncate{}
data = {k1 = 'v1', k2 = 'v2'}
t:insert{1, msgpack.encode(data)}

function test()
    local result = t:get{1}
    return msgpack.decode(result[2])
end

Calling function test() from Tarantool console works fine:

tarantool > test()

---
- {k1: v1, k2: 'v2'}
- 14
...

But there's a problem when I using Tarantool php module:

php> $r = $t->call('test');
PHP Warning:  Uncaught exception 'Exception' with message 'Query error 22: Tuple/Key must be  MsgPack array' in php shell code:1
Stack trace:
#0 php shell code(1): Tarantool->call('test')
#1 {main}
 thrown in php shell code on line 1

Encoding works fine.

I tried to use a PECL version and build an extension by myself.

PHP version:

$ php -v
PHP 5.6.0-1+deb.sury.org~trusty+1 (cli) (built: Aug 28 2014 14:55:42)

Tarantool version:

$ tarantool --version
Tarantool 1.6.3-486-g77b404b
Target: Linux-x86_64-RelWithDebugInfo
Build options: cmake . -DCMAKE_INSTALL_PREFIX=/usr -DENABLE_TRACE=ON -DENABLE_BACKTRACE=ON
Compiler: /usr/lib/ccache/gcc /usr/lib/ccache/c++
C_FLAGS: -fno-omit-frame-pointer -fno-stack-protector -fexceptions -funwind-tables -fopenmp -msse2 -std=c11 -Wall -Wextra -Wno-sign-compare -Wno-strict-aliasing -fno-gnu89-inline
CXX_FLAGS: -fno-omit-frame-pointer -fno-stack-protector -fexceptions -funwind-tables -fopenmp -msse2 -std=c++11 -Wall -Wextra -Wno-sign-compare -Wno-strict-aliasing -Wno-invalid-offsetof

Issue with string field

Config:

#Profile space
space[4].enabled = "true"
space[4].cardinality = "0"
space[4].estimated_rows = "0"
# idProject, idProfile
space[4].index[0].type = "HASH"
space[4].index[0].unique = "true"
space[4].index[0].key_field[0].fieldno = "0"
space[4].index[0].key_field[0].type = "NUM"
space[4].index[0].key_field[1].fieldno = "1"
space[4].index[0].key_field[1].type = "STR"

Request example:

  • Console
$ tarantool -p 33013
localhost> lua box.select(4, 0, 100, '10000000')

---
 - 100: {3472328296227680305, 100, 1}
...
  • Php
$tnt = new Tarantool('127.0.0.1', 33013);
var_dump($tnt->select(4, 0, array(100, '10000000')));

// output:
array(2) {
  ["count"]=>
  int(1)
  ["tuples_list"]=>
  array(1) {
    [0]=>
    array(4) {
      [0]=>
      int(100)
      [1]=>
      int(0) // expect '10000000' here
      [2]=>
      int(100)
      [3]=>
      int(1)
    }
  }
}

$ php -v
PHP 5.3.10-1ubuntu3.8 with Suhosin-Patch (cli) (built: Sep 4 2013 20:00:51)
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies
with Xdebug v2.1.0, Copyright (c) 2002-2010, by Derick Rethans

Building latest tarantool-php with php 5.5.30 - tests failed, php module segfaults

$ php --version
PHP 5.5.30-1+deb.sury.org~trusty+1 (cli) (built: Oct  4 2015 16:23:01) 
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2015 Zend Technologies
    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend Technologies

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 14.04.3 LTS
Release:    14.04
Codename:   trusty

$ tarantool --version
Tarantool 1.6.5
Target: Linux-x86_64-Debug
Build options: cmake . -DCMAKE_INSTALL_PREFIX=/usr/local -DENABLE_TRACE=ON -DENABLE_BACKTRACE=ON
Compiler: /usr/bin/cc /usr/bin/c++
C_FLAGS: -fno-omit-frame-pointer -fno-stack-protector -fexceptions -funwind-tables -fopenmp -msse2 -std=c11 -Wall -Wextra -Wno-sign-compare -Wno-strict-aliasing -fno-gnu89-inline -Werror
CXX_FLAGS: -fno-omit-frame-pointer -fno-stack-protector -fexceptions -funwind-tables -fopenmp -msse2 -std=c++11 -Wall -Wextra -Wno-sign-compare -Wno-strict-aliasing -Wno-invalid-offsetof -Werror

$ git checkout master

$ ./configure
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for a sed that does not truncate output... /bin/sed
checking for cc... cc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether cc accepts -g... yes
checking for cc option to accept ISO C89... none needed
checking how to run the C preprocessor... cc -E
checking for icc... no
checking for suncc... no
checking whether cc understands -c and -o together... yes
checking for system library directory... lib
checking if compiler supports -R... no
checking if compiler supports -Wl,-rpath,... yes
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
checking for PHP prefix... /usr
checking for PHP includes... -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib
checking for PHP extension directory... /usr/lib/php5/20121212
checking for PHP installed headers prefix... /usr/include/php5
checking if debug is enabled... no
checking if zts is enabled... no
checking for re2c... no
configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
checking for gawk... no
checking for nawk... nawk
checking if nawk is broken... no
checking for tarantool support... yes, shared
checking how to print strings... printf
checking for a sed that does not truncate output... (cached) /bin/sed
checking for fgrep... /bin/grep -F
checking for ld used by cc... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B
checking the name lister (/usr/bin/nm -B) interface... BSD nm
checking whether ln -s works... yes
checking the maximum length of command line arguments... 1572864
checking whether the shell understands some XSI constructs... yes
checking whether the shell understands "+="... yes
checking how to convert x86_64-unknown-linux-gnu file names to x86_64-unknown-linux-gnu format... func_convert_file_noop
checking how to convert x86_64-unknown-linux-gnu file names to toolchain format... func_convert_file_noop
checking for /usr/bin/ld option to reload object files... -r
checking for objdump... objdump
checking how to recognize dependent libraries... pass_all
checking for dlltool... no
checking how to associate runtime and link libraries... printf %s\n
checking for ar... ar
checking for archiver @FILE support... @
checking for strip... strip
checking for ranlib... ranlib
checking for gawk... (cached) nawk
checking command to parse /usr/bin/nm -B output from cc object... ok
checking for sysroot... no
checking for mt... mt
checking if mt is a manifest tool... no
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking for dlfcn.h... yes
checking for objdir... .libs
checking if cc supports -fno-rtti -fno-exceptions... no
checking for cc option to produce PIC... -fPIC -DPIC
checking if cc PIC flag -fPIC -DPIC works... yes
checking if cc static flag -static works... yes
checking if cc supports -c -o file.o... yes
checking if cc supports -c -o file.o... (cached) yes
checking whether the cc linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... no
configure: creating ./config.status
config.status: creating config.h
config.status: config.h is unchanged
config.status: executing libtool commands

$ make
/bin/bash /home/thefish/projects/adonweb/overdog/tmp/tarantool-php/libtool --mode=compile cc  -I. -I/home/thefish/projects/adonweb/overdog/tmp/tarantool-php -DPHP_ATOM_INC -I/home/thefish/projects/adonweb/overdog/tmp/tarantool-php/include -I/home/thefish/projects/adonweb/overdog/tmp/tarantool-php/main -I/home/thefish/projects/adonweb/overdog/tmp/tarantool-php -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -I/src/third_party  -DHAVE_CONFIG_H  -g -O2   -c /home/thefish/projects/adonweb/overdog/tmp/tarantool-php/src/tarantool_msgpack.c -o src/tarantool_msgpack.lo 
libtool: compile:  cc -I. -I/home/thefish/projects/adonweb/overdog/tmp/tarantool-php -DPHP_ATOM_INC -I/home/thefish/projects/adonweb/overdog/tmp/tarantool-php/include -I/home/thefish/projects/adonweb/overdog/tmp/tarantool-php/main -I/home/thefish/projects/adonweb/overdog/tmp/tarantool-php -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -I/src/third_party -DHAVE_CONFIG_H -g -O2 -c /home/thefish/projects/adonweb/overdog/tmp/tarantool-php/src/tarantool_msgpack.c  -fPIC -DPIC -o src/.libs/tarantool_msgpack.o
/bin/bash /home/thefish/projects/adonweb/overdog/tmp/tarantool-php/libtool --mode=compile cc  -I. -I/home/thefish/projects/adonweb/overdog/tmp/tarantool-php -DPHP_ATOM_INC -I/home/thefish/projects/adonweb/overdog/tmp/tarantool-php/include -I/home/thefish/projects/adonweb/overdog/tmp/tarantool-php/main -I/home/thefish/projects/adonweb/overdog/tmp/tarantool-php -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -I/src/third_party  -DHAVE_CONFIG_H  -g -O2   -c /home/thefish/projects/adonweb/overdog/tmp/tarantool-php/src/tarantool_manager.c -o src/tarantool_manager.lo 
libtool: compile:  cc -I. -I/home/thefish/projects/adonweb/overdog/tmp/tarantool-php -DPHP_ATOM_INC -I/home/thefish/projects/adonweb/overdog/tmp/tarantool-php/include -I/home/thefish/projects/adonweb/overdog/tmp/tarantool-php/main -I/home/thefish/projects/adonweb/overdog/tmp/tarantool-php -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -I/src/third_party -DHAVE_CONFIG_H -g -O2 -c /home/thefish/projects/adonweb/overdog/tmp/tarantool-php/src/tarantool_manager.c  -fPIC -DPIC -o src/.libs/tarantool_manager.o
/bin/bash /home/thefish/projects/adonweb/overdog/tmp/tarantool-php/libtool --mode=compile cc  -I. -I/home/thefish/projects/adonweb/overdog/tmp/tarantool-php -DPHP_ATOM_INC -I/home/thefish/projects/adonweb/overdog/tmp/tarantool-php/include -I/home/thefish/projects/adonweb/overdog/tmp/tarantool-php/main -I/home/thefish/projects/adonweb/overdog/tmp/tarantool-php -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -I/src/third_party  -DHAVE_CONFIG_H  -g -O2   -c /home/thefish/projects/adonweb/overdog/tmp/tarantool-php/src/tarantool_schema.c -o src/tarantool_schema.lo 
libtool: compile:  cc -I. -I/home/thefish/projects/adonweb/overdog/tmp/tarantool-php -DPHP_ATOM_INC -I/home/thefish/projects/adonweb/overdog/tmp/tarantool-php/include -I/home/thefish/projects/adonweb/overdog/tmp/tarantool-php/main -I/home/thefish/projects/adonweb/overdog/tmp/tarantool-php -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -I/src/third_party -DHAVE_CONFIG_H -g -O2 -c /home/thefish/projects/adonweb/overdog/tmp/tarantool-php/src/tarantool_schema.c  -fPIC -DPIC -o src/.libs/tarantool_schema.o
/bin/bash /home/thefish/projects/adonweb/overdog/tmp/tarantool-php/libtool --mode=link cc -DPHP_ATOM_INC -I/home/thefish/projects/adonweb/overdog/tmp/tarantool-php/include -I/home/thefish/projects/adonweb/overdog/tmp/tarantool-php/main -I/home/thefish/projects/adonweb/overdog/tmp/tarantool-php -I/usr/include/php5 -I/usr/include/php5/main -I/usr/include/php5/TSRM -I/usr/include/php5/Zend -I/usr/include/php5/ext -I/usr/include/php5/ext/date/lib -I/src/third_party  -DHAVE_CONFIG_H  -g -O2   -o tarantool.la -export-dynamic -avoid-version -prefer-pic -module -rpath /home/thefish/projects/adonweb/overdog/tmp/tarantool-php/modules  src/tarantool.lo src/tarantool_msgpack.lo src/tarantool_manager.lo src/tarantool_schema.lo src/tarantool_proto.lo src/tarantool_tp.lo src/third_party/msgpuck.lo src/third_party/sha1.lo src/third_party/base64.lo src/third_party/PMurHash.lo 
libtool: link: rm -fr  .libs/tarantool.la .libs/tarantool.lai .libs/tarantool.so
libtool: link: cc -shared  -fPIC -DPIC  src/.libs/tarantool.o src/.libs/tarantool_msgpack.o src/.libs/tarantool_manager.o src/.libs/tarantool_schema.o src/.libs/tarantool_proto.o src/.libs/tarantool_tp.o src/third_party/.libs/msgpuck.o src/third_party/.libs/sha1.o src/third_party/.libs/base64.o src/third_party/.libs/PMurHash.o    -O2   -Wl,-soname -Wl,tarantool.so -o .libs/tarantool.so
libtool: link: ( cd ".libs" && rm -f "tarantool.la" && ln -s "../tarantool.la" "tarantool.la" )
/bin/bash /home/thefish/projects/adonweb/overdog/tmp/tarantool-php/libtool --mode=install cp ./tarantool.la /home/thefish/projects/adonweb/overdog/tmp/tarantool-php/modules
libtool: install: cp ./.libs/tarantool.so /home/thefish/projects/adonweb/overdog/tmp/tarantool-php/modules/tarantool.so
libtool: install: cp ./.libs/tarantool.lai /home/thefish/projects/adonweb/overdog/tmp/tarantool-php/modules/tarantool.la
libtool: finish: PATH="/home/thefish/.cabal/bin:/opt/cabal/1.22/bin:/opt/ghc/7.10.2/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/thefish/golang/bin:/sbin" ldconfig -n /home/thefish/projects/adonweb/overdog/tmp/tarantool-php/modules
----------------------------------------------------------------------
Libraries have been installed in:
   /home/thefish/projects/adonweb/overdog/tmp/tarantool-php/modules

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
     during execution
   - add LIBDIR to the `LD_RUN_PATH' environment variable
     during linking
   - use the `-Wl,-rpath -Wl,LIBDIR' linker flag
   - have your system administrator add LIBDIR to `/etc/ld.so.conf'

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------

Build complete.
Don't forget to run 'make test'.

$ ./test-run.py 
/usr/bin/php
/usr/bin/php -c tarantool.ini /home/thefish/projects/adonweb/overdog/tmp/tarantool-php/test/phpunit.phar
Running '/usr/bin/php -c tarantool.ini /home/thefish/projects/adonweb/overdog/tmp/tarantool-php/test/phpunit.phar'
Running against 5.5.30-1+deb.sury.org~trusty+1.
With ZTS
With Debug
PHP Warning:  Module 'tarantool' already loaded in Unknown on line 0
TAP version 13
not ok 1 - Error: DMLTest
not ok 2 - Error: DMLTest
not ok 3 - Error: DMLTest
not ok 4 - Error: DMLTest
not ok 5 - Error: DMLTest
not ok 6 - Error: DMLTest
not ok 7 - Error: DMLTest
not ok 8 - Error: DMLTest
not ok 9 - Error: DMLTest
not ok 10 - Error: DMLTest
not ok 11 - Error: DMLTest
not ok 12 - Error: DMLTest
not ok 13 - Error: DMLTest
not ok 14 - Error: DMLTest
ok 15 - MockTest::testFoo
ok 16 - MockTest::testDoo
not ok 17 - Error: CreateTest::test_00_create_basic
not ok 18 - Error: CreateTest::test_01_create_test_ping_and_close
ok 19 - CreateTest::test_02_create_error_host
ok 20 - CreateTest::test_03_00_create_error_port
ok 21 - CreateTest::test_03_01_create_error_port
not ok 22 - Error: CreateTest::test_04_create_many_conns
*** Error in `/usr/bin/php': double free or corruption (top): 0x0000000002050150 ***
Aborted (core dumped)

Checking out this commit and building from source passes all tests. Such module works fiine, as far as i can see.

update vs evaluate - большое потребление пямяти

Почему происходит такая разница в использовании памяти.

Вариант 1. Использую функцию update . Затрачено около 90МБ
update

Вариант 2. В php формирую update код на lua и исполняю его функцией evaluate. Затрачено около 3МБ
evaluate

В чем может быть проблема?

Добавить метод конвертирования возвращенного поля в строку

Существует проблема со строками определенной длинны (4, 8 байт), когда клиент не уверен, получил он число или строку. В результате имеем число. Хотелось бы иметь втроенный метод конвертирования этих чисел в строки (когда точно известно, что это должна быть строка).

out-of-sync IDs received from the server

It seems that somehow it's possible to get out-of-sync replies from the server. We haven't really figured how exactly, as it happens under high load, but it's definitely reproducible.
There's an assert() in the sources that checks for exactly that situation, but it's disabled when PHP isn't built with --enable-debug, so basically the extension checks for this situation and does nothing.
I believe at least an exception should be raised in this case or maybe you should even close the connection - you can't continue using it anyway. At least, that's exactly what we've tried to do, but failed due to issue #56 .

Add tarantool-php to Tarantool buildbot

  • Write RPM specs/DEB rules and push they to the repository. Please use package name that confirms official distributive naming conventions (e.g. tarantool-php5 , php-tarantool, etc.)
  • Add this project to build bot (http://build.tarantool.org/)
  • Check that module build and can be installed from tarantool.org repository

PHP. "Failed to parse query" on 1.6.7

On reproducing an example on PHP from the documentation, Tarantool returns an error "Failed to parse query" on any operation (insert, select...).

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.