如何在本地主机窗口中测试我的 cron 作业?(laravel 5.3)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41547245/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I test my cron job in localhost windows? (laravel 5.3)
提问by samuel toh
I create a cron job on laravel 5.3 by editing app\Console\Kernel.php like this :
我通过像这样编辑 app\Console\Kernel.php 在 laravel 5.3 上创建了一个 cron 作业:
<?php
namespace App\Console;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
use DB;
class Kernel extends ConsoleKernel
{
protected $commands = [
//
];
protected function schedule(Schedule $schedule)
{
$schedule->call(function () {
$id = 1;
DB::table('orders')
->where('id', $id)
->update(['status ' => 2, 'canceled_at' => date("Y-m-d H:i:s")]);
})->everyMinute();
}
protected function commands()
{
require base_path('routes/console.php');
}
}
I tried to check on the table in the database, but it does not update
我试图检查数据库中的表,但它没有更新
How can I test my cron job?
如何测试我的 cron 工作?
回答by AddWeb Solution Pvt Ltd
You can follow below steps:
您可以按照以下步骤操作:
1) You can run php artisan list
command in cmd and find your cron.
1)您可以php artisan list
在cmd中运行命令并找到您的cron。
2) After find your cron, then you can run php artisan yourcron
.
2)找到你的cron后,你就可以运行了php artisan yourcron
。
You can follow this linkfor more details about cron job.
您可以点击此链接了解有关 cron 作业的更多详细信息。
Hope this work for you!
希望这对你有用!
回答by Orbán Zoltán
Go to the project directory and run
进入项目目录并运行
php /path/to/artisan schedule:run
More info about that: https://laravel.com/docs/5.3/scheduling
回答by Priyank lohan
hey you can create log file too at the time of defining cron. as i ahve created mine...
嘿,您也可以在定义 cron 时创建日志文件。因为我已经创造了我的...
* * * * * php /var/www/html/sharep/artisan ElasticSearch:ElasticSearchData >> /var/www/html/sharep.log 2>&1
this cron run after 1 minute. and the logs saves in .log file as mention above.
这个 cron 在 1 分钟后运行。并且日志保存在 .log 文件中,如上所述。