Skip to content

Instantly share code, notes, and snippets.

@localdisk
Created July 20, 2016 07:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save localdisk/77aa7bf501bd55bd59558c996af77e6c to your computer and use it in GitHub Desktop.
Save localdisk/77aa7bf501bd55bd59558c996af77e6c to your computer and use it in GitHub Desktop.
cursor メソッド
<?php
namespace App\Console\Commands;
use App\Post;
use Illuminate\Console\Command;
class FetchPost extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'fetch:posts';
/**
* The console command description.
*
* @var string
*/
protected $description = 'fetch post';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
// 死ぬ Allowed memory size of 536870912 bytes exhausted (tried to allocate 20480 bytes)
$posts = Post::all();
// 死なない
$posts = Post::cursor();
foreach ($posts as $post) {
$this->info($post->body);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment