[英]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.