-
-
Save jmikola/9ab33101944a10f79a96 to your computer and use it in GitHub Desktop.
Inserting randomized fixture data into MongoDB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"require": { | |
"ext-mongo": "~1.5", | |
"fzaninotto/faker": "~1.0" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
for ($i = 0; $i < 10; $i++) { | |
if ( ! pcntl_fork()) { | |
break; | |
} | |
} | |
require_once __DIR__ . "/vendor/autoload.php"; | |
$faker = Faker\Factory::create(); | |
$mc = new MongoClient(); | |
$coll = $mc->test->php1164; | |
for ($i = 0; $i < 10000; $i++) { | |
if ($i % 1000 === 0) { | |
if (isset($batch)) { | |
printf("%s\n", json_encode($batch->execute())); | |
} | |
$batch = new MongoInsertBatch($coll); | |
} | |
$batch->add(['text' => $faker->paragraphs(5)]); | |
} | |
if (isset($batch)) { | |
printf("%s\n", json_encode($batch->execute())); | |
} | |
$result = $batch->execute(); | |
var_dump($result); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment