[英]How can I test my cron job in localhost windows? (laravel 5.3)
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工作?
You can follow below steps: 您可以按照以下步骤操作:
1) You can run php artisan list
command in cmd and find your cron. 1)您可以在cmd中运行php artisan list
命令并找到您的cron。
2) After find your cron, then you can run php artisan yourcron
. 2)找到您的cron之后,即可运行php artisan yourcron
。
You can follow this link for more details about cron job. 您可以单击此链接以获取有关cron作业的更多详细信息。
Hope this work for you! 希望这项工作对您有帮助!
Go to the project directory and run 转到项目目录并运行
php /path/to/artisan schedule:run
More info about that: https://laravel.com/docs/5.3/scheduling 有关此的更多信息: https : //laravel.com/docs/5.3/scheduling
hey you can create log file too at the time of defining cron. 嘿,您在定义cron时也可以创建日志文件。 as i ahve created mine... 当我创造了我的...
* * * * * php /var/www/html/sharep/artisan ElasticSearch:ElasticSearchData >> /var/www/html/sharep.log 2>&1
this cron run after 1 minute. 1分钟后,此cron运行。 and the logs saves in .log file as mention above. 日志如上所述保存在.log文件中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.