简体   繁体   中英

Laravel 5 How to run a php file via scheduler

First time ever setting up a cron/scheduler. How do I run a php file with the scheduler? This is what I see in Laravel's documentation...

Entered the following command via Putty/SSH...

php /path/to/artisan schedule:run >> /dev/null 2>&1

Now... In the Kernel.php file... do I simply add the path to the php file that I want to run in the statement below?

$schedule->exec('node /home/forge/script.js')->daily();

After a few days... I have it working.

I set up the cron job in my cpanel. I set it up to run every minute so I could get good feedback on what I was doing wrong. I created a text file to record the errors.

php /home/accountname/artisan schedule:run >> /home/accountname/cron-output.txt 2>&1

I thought I had to call the php file where the method was located. However, to call a method, you must put the full path to the method like so...

$schedule->call('App\Http\Controllers\ParseDataFeed@parseFeed')
        ->dailyAt('15:00')
        ->sendOutputTo('cron-output.txt');

I hope this helps someone.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM