我在 Laravel 5.2 中创建了一个在特定时间后运行的示例计划作业。这通过 artisan
命令在 localhost
上运行良好。
我在本地服务器上运行这个命令:
php artisan 演示:Cron
现在我将此任务添加到 HostGator 托管服务器上的 cPanel 高级选项 cron 作业中。但它不起作用。
这是我正在尝试的命令:
cd/home/pofindia/public_html/beta-var1/&&/usr/local/bin/php artisan Demo:Cron
PHP 版本:默认 5.4。 这是我的示例文件
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use DB;
class DemoCron extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'demo:cron';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
DB::table('items')->insert(['name'=>'hello new']);
$this->info('Demo:Cron Cummand Run successfully!');
}
}
最佳答案
运行
which php
要查看 php 可执行文件的位置,请复制该路径。
crontab -e
(我假设这是您的 artisan 所在的项目根目录/home/pofindia/public_html/beta-var1/ 但这需要您向其中添加 artisan ,因为 /home/pofindia/public_html/beta-var1/artisan)
添加crontab条目
* * * * * /usr/local/bin/php /home/pofindia/public_html/beta-var1/artisan Demo:Cron
实际上你在这里所做的只是提供绝对路径
关于php - 如何在 hostgator 托管服务器 cpanel 上的 cron 作业上运行 laravel 5.2 artisan 命令?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38804387/