Created
July 20, 2016 07:41
-
-
Save localdisk/77aa7bf501bd55bd59558c996af77e6c to your computer and use it in GitHub Desktop.
cursor メソッド
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 | |
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