2

I am setting cron job first time in Laravel 5.2. As per their docs, I have modified my app/Console/Kernel.php as -

    protected $commands = [
         \App\Console\Commands\Inspire::class,
    ];

    protected function schedule(Schedule $schedule)
    {            
        $schedule->call(function() {
                $myfile = fopen("testfile.txt", "w");
            }
        )->everyMinute();
    }

And start scheduler -

* * * * * php /var/www/html/{project_dir}/artisan schedule:run 1>> /dev/null 2>&1

I want to run this cron every minute. But it is totally not working. If I tried with php artisan schedule:run cron runs and "testfile.txt" generated in root folder. But why it is not calling automatically every minute? I don't know what's going wrong here.

Any help is appreciated.

Thanks.

SandyK
  • 413
  • 8
  • 23
  • try "> /dev/null" instantiate of 1>> /dev/null 2>&1 – Dipesh Shihora Nov 24 '16 at 13:02
  • Possible duplicate of [Running a cron every 30 seconds](http://stackoverflow.com/questions/9619362/running-a-cron-every-30-seconds) – AddWeb Solution Pvt Ltd Nov 24 '16 at 13:02
  • @Dipesh : tried with same, but no use – SandyK Nov 24 '16 at 13:24
  • 1
    I think you might want to use fclose to close the file when your done writing to it - also a note on the php manual "using fopen in 'w' mode will NOT update the modification time (filemtime) of a file like you may expect. You may want to issue a touch() after writing and closing the file which update its modification time." http://php.net/manual/en/function.fopen.php http://php.net/manual/en/function.fclose.php – Jonny C Nov 24 '16 at 14:06
  • Also I'd check to see if the file is put in an unexpected place by the cronjob - running `php artisan schedule:run` puts it in the root of the website - when cron runs creates the file elsewhere – Jonny C Nov 24 '16 at 14:26

0 Answers0