1. Go to this page and download the library: Download tarantool/client library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
tarantool / client example snippets
use Tarantool\Client\Client;
$client = Client::fromDefaults();
use MessagePack\BufferUnpacker;
use MessagePack\Packer;
use Tarantool\Client\Client;
use Tarantool\Client\Connection\StreamConnection;
use Tarantool\Client\Handler\DefaultHandler;
use Tarantool\Client\Handler\MiddlewareHandler;
use Tarantool\Client\Middleware\AuthenticationMiddleware;
use Tarantool\Client\Middleware\RetryMiddleware;
use Tarantool\Client\Packer\PurePacker;
$connection = StreamConnection::createTcp('tcp://127.0.0.1:3301', [
'socket_timeout' => 5.0,
'connect_timeout' => 5.0,
// ...
]);
$pureMsgpackPacker = new Packer();
$pureMsgpackUnpacker = new BufferUnpacker();
$packer = new PurePacker($pureMsgpackPacker, $pureMsgpackUnpacker);
$handler = new DefaultHandler($connection, $packer);
$handler = MiddlewareHandler::append($handler, [
RetryMiddleware::exponential(3),
new AuthenticationMiddleware('<username>', '<password>'),
// ...
]);
$client = new Client($handler);
use Tarantool\Client\Keys;
use Tarantool\Client\Request\CallRequest;
...
$request = new CallRequest('box.stat');
$response = $handler->handle($request);
$data = $response->getBodyField(Keys::DATA);
use Tarantool\Client\Client;
use Tarantool\Client\Middleware\AuthenticationMiddleware;
$client = Client::fromDefaults()->withMiddleware(
new AuthenticationMiddleware('<username>', '<password>')
);
use Tarantool\Client\Client;
use Tarantool\Client\Middleware\FirewallMiddleware;
use Tarantool\Client\Middleware\LoggingMiddleware;
use Tarantool\Client\Middleware\RetryMiddleware;
...
$client = Client::fromDefaults()->withMiddleware(
FirewallMiddleware::allowReadOnly(),
RetryMiddleware::linear(),
new LoggingMiddleware($logger)
);
$client->execute('CREATE TABLE users ("id" INTEGER PRIMARY KEY AUTOINCREMENT, "name" VARCHAR(50))');
$stmt = $client->prepare('INSERT INTO users VALUES(null, ?)');
for ($i = 1; $i <= 100; ++$i) {
$stmt->execute("name_$i");
// You can also use executeSelect() and executeUpdate(), e.g.:
// $lastInsertIds = $stmt->executeUpdate("name_$i")->getAutoincrementIds();
}
$stmt->close();
// Note the SEQSCAN keyword in the query. It is available as of Tarantool 2.11.
// If you are using an older version of Tarantool, omit this keyword.
$result = $client->executeQuery('SELECT COUNT("id") AS "cnt" FROM SEQSCAN users');
printf("Result: %s\n", json_encode($result[0]));