-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbatch.php
53 lines (42 loc) · 1.71 KB
/
batch.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
<?php
/**
* Sandro Keil (https://sandro-keil.de)
*
* @link http://github.com/sandrokeil/arangodb-php-client for the canonical source repository
* @copyright Copyright (c) 2018-2020 Sandro Keil
* @license http://github.com/sandrokeil/arangodb-php-client/blob/master/LICENSE.md New BSD License
*/
require __DIR__ . '/init.php';
use ArangoDb\Guard\SuccessHttpStatusCode;
use ArangoDb\Http\BatchResult;
use ArangoDb\Type\Batch;
use ArangoDb\Type\Collection;
use ArangoDb\Type\Document;
use ArangoDbTest\TestUtil;
$client = TestUtil::getClient();
$requestFactory = TestUtil::getRequestFactory();
$responseFactory = TestUtil::getResponseFactory();
$streamFactory = TestUtil::getStreamFactory();
$streamHandlerFactory = TestUtil::getStreamHandlerFactory();
$collectionName = 'users';
$guard = SuccessHttpStatusCode::withoutContentId();
try {
$t1 = microtime(true);
// creating types for batch request
$types = [
Collection::create($collectionName)->useGuard($guard),
Document::create($collectionName, ['name' => 'foo', 'id' => 1])->useGuard($guard),
Document::create($collectionName, ['name' => 'qux', 'id' => 6])->useGuard($guard),
Document::create($collectionName, ['name' => 'quu', 'id' => 7])->useGuard($guard),
];
$batch = Batch::fromTypes(...$types);
echo 'SENDING BATCH WITH CREATING COLLECTION ' . $collectionName . ' and 3 docs ...';
$batchResponse = $client->sendType($batch);
echo ' Status Code: ' . $batchResponse->getStatusCode() . PHP_EOL;
print_r($batchResponse->getBody()->getContents());
$t2 = microtime(true);
$totalTime = ($t2 - $t1);
echo sprintf('Execution time %s s', $totalTime) . PHP_EOL;
} catch (\Throwable $e) {
print_r($e);
}