[英]Laravel Create cron job on shared hosting
I started to learnig "Scheduling task" chapter in Laravel docs.我开始学习 Laravel 文档中的“调度任务”一章。 On localhost xampp project I created command which delete last inserted row in table在 localhost xampp 项目上,我创建了删除表中最后插入行的命令
class em extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'my:em';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Delete task';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
DB::table('task')->orderBy('id', 'desc')->limit(1)->delete();
echo 'done';
}
} }
Then I added it to Kernel然后我将它添加到内核
class Kernel extends ConsoleKernel
{
/**
* The Artisan commands provided by your application.
*
* @var array
*/
protected $commands = [
//
];
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
$schedule->command('my:em')->everyMinute();
}
/**
* Register the commands for the application.
*
* @return void
*/
protected function commands()
{
$this->load(__DIR__.'/Commands');
require base_path('routes/console.php');
}
} }
Then I created .bat file with php artisan schedule:run command and added it to task manager in windows.然后我使用php artisan schedule:run命令创建了 .bat 文件并将其添加到 Windows 中的任务管理器。 Everything worked fine.一切正常。
Next I uploaded this project to shared server with ssh access and cron jobs feature.接下来,我将此项目上传到具有 ssh 访问和 cron 作业功能的共享服务器。 I want to use php artisan schedule:run but I receive messsage: No scheduled commands are ready to run .我想使用php artisan schedule:run但我收到消息:没有计划的命令准备运行。
On the other hand The server has a in-build creator of cron jobs.另一方面,服务器有一个内置的 cron 作业创建者。 I can create task.我可以创建任务。 I must just set date and time and fullfill the field translated in English for "command" (see picture below).我必须设置日期和时间并填写英文翻译的“命令”字段(见下图)。 I have no idea what should I input here.我不知道我应该在这里输入什么。 Please help (appson is my domain name).请帮忙(appson是我的域名)。
The cron entry to add can be found in the documentation要添加的 cron 条目可以在文档中找到
https://laravel.com/docs/6.x/scheduling#introduction https://laravel.com/docs/6.x/scheduling#introduction
* * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1
If you can't access something like crontab
, you should just be able to add this entry in your server's "in-build creator of cron jobs"如果您无法访问诸如crontab
,您应该能够在服务器的“内置 cron 作业创建者”中添加此条目
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.