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?
我正在努力让Laravel 5.1任务调度工作在IIS上。当我使用Windows任务管理器运行批处理文件时,它只会运行一次任务。我怎样才能把每分钟的时间都用在工作上呢?
Windows batch file:
Windows批处理文件:
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');
}
4 个解决方案
#1
4
Take a look at the task scheduler doc.
看一看任务调度程序文档。
Starting The Scheduler
开始调度器
Here is the only Cron entry you need to add to your server:
这里是您需要添加到服务器的唯一Cron条目:
* * * * * php /path/to/artisan schedule:run >> /dev/null 2>&1
运行>> /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.
这个Cron将每分钟调用Laravel命令调度器。然后,Laravel评估你的计划任务,并运行到期的任务。
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.
在您的情况中,您使用Windows任务调度程序而不是Cron,但重要的是调用artisan调度:每分钟运行一次。每次运行此命令时,它都会检查其调度并运行所添加的适当任务/命令。
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.
artisan调度:运行不会启动一个长时间运行的进程,它在执行任务之前一直保持运行,直到您杀死它为止。就像我说的,它需要每分钟都被调用。
#2
4
You need to create a scheduled task that will execute that batch file every minute.
您需要创建一个预定的任务,它将每分钟执行该批处理文件。
To do so :
这样做:
-
Press Win + R and run
taskschd.msc
按Win + R,运行taskschd.msc。
-
In the right panel click Create Basic Task and give it a Name + Description.
在右边的面板中,点击创建基本任务,并给它一个名称+描述。
-
Click Next and select Start a Program option, then navigate to the batch file and select it. No need to fill the other fields.
单击Next并选择Start a程序选项,然后导航到批处理文件并选择它。不需要填充其他字段。
-
Select "Open the properties of this task..." and then Finish.
选择“打开这个任务的属性……”然后完成。
-
On the Trigger tab, you can change between Daily or At Logon (as I do).
在触发器选项卡上,您可以在每天或登录时进行更改(就像我一样)。
Here is the part that's not documented, open the dropbox and insert 1 using the keyboard, this is the only way to set the repeat time at 1 minute (even if the dropdown doesn't list it).
这是没有记录的部分,打开dropbox并使用键盘插入1,这是在1分钟内设置重复时间的唯一方法(即使下拉列表没有列出)。
Larevel
needs thecronjob
to run every minute, otherwise it won't work as expected.Larevel需要cronjob每分钟运行一次,否则它将无法正常工作。
Also check "Indefinitely" to run it forlifetime.
还要检查“无限期”运行它的生命周期。
Hope it helps.
希望它可以帮助。
The Windows Task Scheduler Help is here, if you run into trouble.
如果您遇到麻烦,Windows任务调度器会帮助您。
#3
0
Windows does support Laravel Scheduler but, you've to run the command on your own for multiple times. Since we can't use Windows Task Scheduler to run for every 1 min as we can do with linux crontab. If you're using windows for development environment and want to test if command is working on not you can try this
Windows确实支持Laravel调度器,但是,您必须自己运行这个命令多次。因为我们不能使用Windows任务调度程序运行每1分钟,就像我们使用linux crontab那样。如果您在开发环境中使用windows,并且想要测试命令是否正在运行,您可以尝试一下。
If you run the
如果你运行这个
php artisan schedule:run
php工匠时间表:运行
command for multiple times by giving a min gap for each trial it'll work.
多次命令,每次试验都有一个最小的间隔。
If you want to run directly the command you can follow this.
如果你想直接运行命令,你可以跟随它。
"path\to\php.exe" "artisan" YourCommand > "NUL" 2>&1 &
“路径\ \ php。您的命令>“NUL”2>&1 &。
You can find path of your php.exe using below step.
您可以找到php的路径。exe使用下面的步骤。
Run "where php.exe" in command prompt
“php运行。exe”在命令提示符
#4
0
I have a single solution Create to file Executable xxx.cmd, Open the file and write the next text.
我有一个单一的解决方案来创建可执行的xxx。打开文件并编写下一个文本。
@echo off
echo - = = = Schedule Run Jobs == = = = -
CD d: && CD \xampp\htdocs\folderlaravel && php artisan schedule:run
timeout 86400
CD d: && CD \xampp\htdocs\folderlaravel && "Schedule.cmd"
pause
@cls
What you do is run and run itself in an infinite loop depending on what timeout you are given. In this case 86400 => 1 day.
您所做的是在一个无限循环中运行和运行,这取决于给定的超时时间。在这种情况下,86400 => 1天。
It is somewhat ambiguous but it works :)
这有点模棱两可,但确实有效。
I hope it works for you.
我希望它对你有用。
#1
4
Take a look at the task scheduler doc.
看一看任务调度程序文档。
Starting The Scheduler
开始调度器
Here is the only Cron entry you need to add to your server:
这里是您需要添加到服务器的唯一Cron条目:
* * * * * php /path/to/artisan schedule:run >> /dev/null 2>&1
运行>> /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.
这个Cron将每分钟调用Laravel命令调度器。然后,Laravel评估你的计划任务,并运行到期的任务。
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.
在您的情况中,您使用Windows任务调度程序而不是Cron,但重要的是调用artisan调度:每分钟运行一次。每次运行此命令时,它都会检查其调度并运行所添加的适当任务/命令。
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.
artisan调度:运行不会启动一个长时间运行的进程,它在执行任务之前一直保持运行,直到您杀死它为止。就像我说的,它需要每分钟都被调用。
#2
4
You need to create a scheduled task that will execute that batch file every minute.
您需要创建一个预定的任务,它将每分钟执行该批处理文件。
To do so :
这样做:
-
Press Win + R and run
taskschd.msc
按Win + R,运行taskschd.msc。
-
In the right panel click Create Basic Task and give it a Name + Description.
在右边的面板中,点击创建基本任务,并给它一个名称+描述。
-
Click Next and select Start a Program option, then navigate to the batch file and select it. No need to fill the other fields.
单击Next并选择Start a程序选项,然后导航到批处理文件并选择它。不需要填充其他字段。
-
Select "Open the properties of this task..." and then Finish.
选择“打开这个任务的属性……”然后完成。
-
On the Trigger tab, you can change between Daily or At Logon (as I do).
在触发器选项卡上,您可以在每天或登录时进行更改(就像我一样)。
Here is the part that's not documented, open the dropbox and insert 1 using the keyboard, this is the only way to set the repeat time at 1 minute (even if the dropdown doesn't list it).
这是没有记录的部分,打开dropbox并使用键盘插入1,这是在1分钟内设置重复时间的唯一方法(即使下拉列表没有列出)。
Larevel
needs thecronjob
to run every minute, otherwise it won't work as expected.Larevel需要cronjob每分钟运行一次,否则它将无法正常工作。
Also check "Indefinitely" to run it forlifetime.
还要检查“无限期”运行它的生命周期。
Hope it helps.
希望它可以帮助。
The Windows Task Scheduler Help is here, if you run into trouble.
如果您遇到麻烦,Windows任务调度器会帮助您。
#3
0
Windows does support Laravel Scheduler but, you've to run the command on your own for multiple times. Since we can't use Windows Task Scheduler to run for every 1 min as we can do with linux crontab. If you're using windows for development environment and want to test if command is working on not you can try this
Windows确实支持Laravel调度器,但是,您必须自己运行这个命令多次。因为我们不能使用Windows任务调度程序运行每1分钟,就像我们使用linux crontab那样。如果您在开发环境中使用windows,并且想要测试命令是否正在运行,您可以尝试一下。
If you run the
如果你运行这个
php artisan schedule:run
php工匠时间表:运行
command for multiple times by giving a min gap for each trial it'll work.
多次命令,每次试验都有一个最小的间隔。
If you want to run directly the command you can follow this.
如果你想直接运行命令,你可以跟随它。
"path\to\php.exe" "artisan" YourCommand > "NUL" 2>&1 &
“路径\ \ php。您的命令>“NUL”2>&1 &。
You can find path of your php.exe using below step.
您可以找到php的路径。exe使用下面的步骤。
Run "where php.exe" in command prompt
“php运行。exe”在命令提示符
#4
0
I have a single solution Create to file Executable xxx.cmd, Open the file and write the next text.
我有一个单一的解决方案来创建可执行的xxx。打开文件并编写下一个文本。
@echo off
echo - = = = Schedule Run Jobs == = = = -
CD d: && CD \xampp\htdocs\folderlaravel && php artisan schedule:run
timeout 86400
CD d: && CD \xampp\htdocs\folderlaravel && "Schedule.cmd"
pause
@cls
What you do is run and run itself in an infinite loop depending on what timeout you are given. In this case 86400 => 1 day.
您所做的是在一个无限循环中运行和运行,这取决于给定的超时时间。在这种情况下,86400 => 1天。
It is somewhat ambiguous but it works :)
这有点模棱两可,但确实有效。
I hope it works for you.
我希望它对你有用。