Laravel 5.1任务调度在Windows [英] Laravel 5.1 Task Scheduling on Windows
问题描述
我试图让Laravel 5.1的任务调度在IIS上工作。当我使用Windows任务管理器运行一个批处理文件,它将运行任务一次。我怎样才能得到? - > everyMinute()工作
Windows批处理文件:
CD C:\\的Inetpub \\ MyApp的
C:\\ PROGRA〜2 \\ PHP \\ php.exe的工匠时间表:运行1>> NUL 2 - ;&放大器; 1
内核:
类内核扩展ConsoleKernel
{
保护$命令= [ \\ APP \\控制台\\命令\\ MyCommand ::类, ]; 保护功能表(附表$时间表)
{
$时刻表>指令(测试) - GT; everyMinute();
}
}
命令:
公共职能手柄()
{
登录::信息('测试');
}
看看在任务调度文档。
启动该调度程序
下面是你需要添加到您的服务器的唯一cron项:
* * * * *的PHP /路径/要/工匠时间表:运行>>的/ dev / null的2 - ;&放大器; 1
这cron将会调用Laravel调度命令的每一分钟。然后,Laravel评估您的计划任务和运行到期的任务。
块引用>在你的情况,你可以使用Windows任务调度程序,而不是克朗,但最重要的事情是调用
工匠时间表:运行
的每一分钟。每次运行此命令时,它会检查其调度和运行到期的任务/命令说。
工匠时间表:运行
不启动长期运行的过程,直到你杀了它的停留活着的运行任务。正如我所说的,它需要被调用的每一分钟。I'm trying to get Laravel 5.1 Task Scheduling working on IIS. When I run a batch file using Windows task manager it will run the task one time only. How can I get ->everyMinute() to work?
Windows batch file:
cd c:\inetpub\myapp c:\PROGRA~2\PHP\php.exe artisan schedule:run 1>> NUL 2>&1
The kernel:
class Kernel extends ConsoleKernel { protected $commands = [ \App\Console\Commands\MyCommand::class, ]; protected function schedule(Schedule $schedule) { $schedule->command('test')->everyMinute(); } }
The command:
public function handle() { log::info('test'); }
解决方案Take a look at the task scheduler doc.
Starting The Scheduler
Here is the only Cron entry you need to add to your server:
* * * * * php /path/to/artisan schedule:run >> /dev/null 2>&1
This Cron will call the Laravel command scheduler every minute. Then, Laravel evaluates your scheduled tasks and runs the tasks that are due.
In your case, you use the Windows task scheduler instead of Cron but the important thing is to call
artisan schedule:run
every minute. Each time this command is run, it checks its schedule and runs the due tasks/commands added.
artisan schedule:run
does not start a long-running process that stays alive to runs tasks until you kill it. As I said, it needs to be called every minute.这篇关于Laravel 5.1任务调度在Windows的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!