forked from arangodb/arangodb-php
-
Notifications
You must be signed in to change notification settings - Fork 0
/
http-test.php
49 lines (37 loc) · 1.34 KB
/
http-test.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
<?php
namespace ArangoDBClient;
require __DIR__ . '/init.php';
$n = 100 * 1000; // number of documents
try {
// turn off tracing... it's too verbose here
unset($connectionOptions[ConnectionOptions::OPTION_TRACE]);
$connection = new Connection($connectionOptions);
$collectionHandler = new CollectionHandler($connection);
$handler = new DocumentHandler($connection);
// set up a document collection "test"
// first try to remove it if it already exists
try {
$collectionHandler->drop('test');
} catch (\Exception $e) {
// collection may not exist. we don't care here
}
// now create the collection
$collection = new Collection('test');
$collectionHandler->create($collection);
echo "creating $n documents" . PHP_EOL;
$time = microtime(true);
// create lots of documents sequentially
// this issues lots of HTTP requests to the server so we
// can test the HTTP layer
for ($i = 0; $i < $n; ++$i) {
$document = new Document(['value' => 'test' . $i]);
$handler->save('test', $document);
}
echo 'creating documents took ' . (microtime(true) - $time) . ' s' . PHP_EOL;
} catch (ConnectException $e) {
print $e . PHP_EOL;
} catch (ServerException $e) {
print $e . PHP_EOL;
} catch (ClientException $e) {
print $e . PHP_EOL;
}