[英]Laravel Create cron job on shared hosting
我开始学习 Laravel 文档中的“调度任务”一章。 在 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';
}
}
然后我将它添加到内核
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');
}
}
然后我使用php artisan schedule:run命令创建了 .bat 文件并将其添加到 Windows 中的任务管理器。 一切正常。
接下来,我将此项目上传到具有 ssh 访问和 cron 作业功能的共享服务器。 我想使用php artisan schedule:run但我收到消息:没有计划的命令准备运行。
另一方面,服务器有一个内置的 cron 作业创建者。 我可以创建任务。 我必须设置日期和时间并填写英文翻译的“命令”字段(见下图)。 我不知道我应该在这里输入什么。 请帮忙(appson是我的域名)。
要添加的 cron 条目可以在文档中找到
https://laravel.com/docs/6.x/scheduling#introduction
* * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1
如果您无法访问诸如crontab
,您应该能够在服务器的“内置 cron 作业创建者”中添加此条目
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.