last day (15 days later) » 

10:43 PM
0
A: Task Scheduling : Laravel 5.3

Bara' ayyashin my Console Routes in file console.php i have this command: Artisan::command('writeFile', function () { Storage::disk('local')->put('file.txt', 'this is text !'); }); in my Kernal.php i have this: protected function schedule(Schedule $schedule) { $schedule->command('writeFile') ...

 
when will the WriteFile() function run ? It is never been called
 
it should be like this : Artisan::command('writeFile', function ($project) { Storage::disk('local')->put('newfile.txt', $txt); }); follow this link for more
 
Could you please update Kernel class in your answer from scratch?
It creates the file after the command runs on cmd. Then it never run after each minute. I can see the file was created under app folder in storage. But it never reruns automatically.
 
you need add cron job to make php artisan schedule:run runs every minute
 
could you please give guidelines to associate the schedule:run with cron job?
 
10:43 PM
you need to edit your crontab using command from cmd crontab -e then add this command * * * * * php /path/to/artisan schedule:run >> /dev/null 2>&1 also you can watch this video for full example with registering run as cron job
 
could i use ->cron('* * * * * *'); method listed here laravel.com/docs/5.3/scheduling like this? $schedule->command('writeFile')->cron('* * * * *'); I tried but not working.
 
hi there
 
hi. i am in localhost at the moment.
could I setup cron in localhost?
 
are you using unix ?
 
window
$schedule->command('writeFile')->everyMinute(); I was using everyMinute() function, does not this means that the function must run after each min without any cron job?
if not then what's the use of function everyMinute() ?
 
10:47 PM
yes.. BUT what is triggering this command is another command which is php artisan schedule:run
and you need your machine to keep calling that command in order to take care of your laravel commands
 
php artisan schedule:run has ran the code under method: protected function schedule(Schedule $schedule) and now what is everyMinute() method's role?
 
everyMinute() informs laravel to schedule your command, and it will wait to php artisan schedule:run to be called again in order to fire the scheduled commands
 
that means there is no difference between $schedule->command('writeFile')->everyMinute(); and $schedule->command('writeFile'); ?
 
of course you need everyMinute(); but in order to enable laravel to handle your scheduled commands, you need to make sure that "php artisan schedule:run" is called every minute
without making cron job runs every minute for "php artisan schedule:run", no commands will be executed automatically !
you can watch this vedio to understand what is going on with scheduler in laravel https://laracasts.com/series/intermediate-laravel/episodes/1 , watch the first two episodes.. its free..

and you can see this answer for crontab in windows : http://stackoverflow.com/questions/132971/what-is-the-windows-version-of-cron
 
could i ask you to come on team viewer?
 
11:01 PM
in my timezone its too late and i have to go sleep, can we do this tomorrow ?
 
hi
I saw there was crontab command used in console.
but i checked my side that was not there.
 
the only thing you have to do now is to find how to do a cron in windows, in my mac i did this "* * * * * /usr/bin/php /Users/baraayyash/Desktop/mzadat/artisan schedule:run > /dev/null 2>&1 &"


and everything is working just fine
 
ok, Is there any way to do it on godaddy?
godaddy server.
 
11:18 PM
if the server runs on linux, sure.. go to terminal

do this command : crontab -e

then add this line : * * * * * /usr/bin/php /Users/baraayyash/Desktop/mzadat/artisan schedule:run > /dev/null 2>&1 &

make sure to replace my foldar path with yours

save the file, and everything will work as you want
i am assuming that you can ssh to the server right? and can use the server's terminal
 
i am on godaddy server right now.
no idea about ssh so
i am accessing the server directly.
 
i gotta go now, can we talk tomorrow? we will use teamviewer
 
i would really appreciate if u could give just 2 mins now
 
oky.. give me the id and password
 
344 741 388
4071
 

last day (15 days later) »