|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace triagens\ArangoDb; |
| 4 | + |
| 5 | +require dirname(__FILE__) . DIRECTORY_SEPARATOR . 'init.php'; |
| 6 | + |
| 7 | +$n = 100 * 1000; // number of documents |
| 8 | + |
| 9 | +try { |
| 10 | + // turn off tracing... it's too verbose here |
| 11 | + unset($connectionOptions[ConnectionOptions::OPTION_TRACE]); |
| 12 | + |
| 13 | + $connection = new Connection($connectionOptions); |
| 14 | + $collectionHandler = new CollectionHandler($connection); |
| 15 | + $handler = new DocumentHandler($connection); |
| 16 | + |
| 17 | + // set up a document collection "test" |
| 18 | + // first try to remove it if it already exists |
| 19 | + try { |
| 20 | + $collectionHandler->drop("test"); |
| 21 | + } |
| 22 | + catch (\Exception $e) { |
| 23 | + // collection may not exist. we don't care here |
| 24 | + } |
| 25 | + |
| 26 | + // now create the collection |
| 27 | + $collection = new Collection("test"); |
| 28 | + $collectionHandler->add($collection); |
| 29 | + |
| 30 | + echo "creating $n documents" . PHP_EOL; |
| 31 | + $time = microtime(true); |
| 32 | + |
| 33 | + // create lots of documents sequentially |
| 34 | + // this issues lots of HTTP requests to the server so we |
| 35 | + // can test the HTTP layer |
| 36 | + for ($i = 0; $i < $n; ++$i) { |
| 37 | + $document = new Document(array("value" => "test" . $i)); |
| 38 | + |
| 39 | + $handler->save("test", $document); |
| 40 | + } |
| 41 | + |
| 42 | + echo "creating documents took " . (microtime(true) - $time) . " s" . PHP_EOL; |
| 43 | + |
| 44 | +} catch (ConnectException $e) { |
| 45 | + print $e . PHP_EOL; |
| 46 | +} catch (ServerException $e) { |
| 47 | + print $e . PHP_EOL; |
| 48 | +} catch (ClientException $e) { |
| 49 | + print $e . PHP_EOL; |
| 50 | +} |
0 commit comments