Skip to content

Instantly share code, notes, and snippets.

@trylik
Created June 7, 2011 10:32
Show Gist options
  • Save trylik/1012011 to your computer and use it in GitHub Desktop.
Save trylik/1012011 to your computer and use it in GitHub Desktop.
mongoDB insert benchmark
<?php
try {
// open connection to MongoDB server
$conn = new Mongo('localhost');
// access database
$db = $conn->benchmark;
// access collection
$collection = $db->coll;
for ($i=0;$i<5000000;$i++) {
// insert a new document
$item = array(
"timestamp" => 1303471614,
"client_ip" => "127.0.0.1",
"host_address" => "http://www.host.url",
"position" => 1,
"user_hash" => 10130347161597979797979797979797,
"host_name" => "www.example.co",
"shop_hash" => "be0290b2320e475736048ecfdf688467",
"shop_product_id" => 1,
"cost" => 0.77
);
$collection->insert($item);
echo $item . "_id";
}
// disconnect from server
$conn->close();
} catch (MongoConnectionException $e) {
die('Error connecting to MongoDB server');
} catch (MongoException $e) {
die('Error: ' . $e->getMessage());
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment