2016-12-01 4 views
1

I am following this tutorial 매분 기능을 예약하십시오. 아래는 localhost에 관한 나의 코드이다.작업 예약 : Laravel 5.3

class Kernel extends ConsoleKernel 
{ 
    protected $commands = [ 
     'App\Console\Commands\Inspire', 
    ]; 

    protected function schedule(Schedule $schedule) 
    { 
     $schedule->call($this->WriteFile())->everyMinute(); 
    } 

    protected function commands() 
    { 
     require base_path('routes/console.php'); 
    } 

    private function WriteFile() { 
     $myfile = fopen("newfile.txt", "w") or die("Unable to open file!"); 
     $txt = "John Doe\n"; 
     fwrite($myfile, $txt); 
     fclose($myfile); 
    } 
} 

txt 파일에 내용이 표시되지 않는 것으로 나타났습니다. 나는 공용 폴더에 txt 파일을 넣었다. 내가 놓친 게 있니? 내가이가 내 Kernal.php에서

Artisan::command('writeFile', function() { 
    Storage::disk('local')->put('file.txt', 'this is text !'); 
}); 

: 파일 console.phpConsole Routes에서

+0

당신은 당신의 서버에 크론 항목을 추가 했습니까? – istaro

+0

이것은 로컬 호스트에 관한 것입니다. – Pankaj

답변

2

내가이 명령을

또한 실행해야
protected function schedule(Schedule $schedule) 
{ 
    $schedule->command('writeFile') 
      ->everyMinute(); 
} 

: php artisan schedule:run

파일이있을 것입니다 경로에 있고 파일은 경로에 있습니다. "/storage/app/file.txt"

파일을 읽을 수3210

: Storage::get('file.txt');

나를 위해 잘 작동 ..이 당신과 함께 작동합니다 희망 :

+0

이렇게해야합니다 :'Artisan :: command ('writefile', function ($ project) { Storage :: disk ('local') -> put ('newfile.txt', $ txt); } ; [더] (https://laravel.com/docs/5.3/artisan) –

+0

에 대한 링크를 따라 가면 'php artisan schedule : run'을 (를) 추가하기 위해 cron 작업을 추가해야합니다. 매분마다 –

+0

을 편집해야합니다. 당신의'crontab'은'crontab -e' 명령을 사용하여 다음 명령을 추가합니다.''* * * * * php/path/to/artisan schedule : 실행 >>/dev/null 2> & 1 ' 도 볼 수 있습니다. 이 [video] (https://www.youtube.com/watch?v=mp-XZm7INl8) cron job –