Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- use Illuminate\Console\Command;
- use Symfony\Component\Console\Input\InputOption;
- use Symfony\Component\Console\Input\InputArgument;
- class Leaktest extends Command {
- /**
- * The console command name.
- *
- * @var string
- */
- protected $name = 'leaktest';
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = 'Reproduction of possible memory leak in Fluent';
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
- /**
- * Execute the console command.
- *
- * @return void
- */
- public function fire()
- {
- switch ($type = $this->argument('type')) {
- case "leak_example":
- \DB::connection()->disableQueryLog();
- for($i = 1; $i < 10; $i++) {
- for ($j = 0; $j < 10000; $j++) {
- $string = microtime();
- \DB::table('test')->insert(['somefield' => $string ]);
- }
- echo "#executions = " . $i * 10000 . " - mem: " . memory_get_usage() . "\n";
- }
- echo "READY\n";
- break;
- case "noleak_example":
- \DB::connection()->disableQueryLog();
- for($i = 1; $i < 10; $i++) {
- for ($j = 0; $j < 10000; $j++) {
- $string = microtime();
- $query = "insert into `test` (`somefield`) values ('{$string}')";
- \DB::connection()->getPdo()->query($query);
- }
- echo "#executions = " . $i * 10000 . " - mem: " . memory_get_usage() . "\n";
- }
- echo "READY\n";
- break;
- default:
- $this->error("Invalid type [$type]");
- }
- $this->info('Ready');
- }
- /**
- * Get the console command arguments.
- *
- * @return array
- */
- protected function getArguments()
- {
- return array(
- array('type', InputArgument::REQUIRED, 'leak_example | noleak_example'),
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment