Swe*_*ety 5 php cron laravel-5.2
我创建了一个示例计划作业,以在 Laravel 5.2 中的特定时间后运行。这localhost通过artisan命令工作正常。
我在本地服务器上运行这个命令:
php artisan Demo: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!');
}
}
Run Code Online (Sandbox Code Playgroud)
跑步
which php
Run Code Online (Sandbox Code Playgroud)
要查看 php 可执行文件的位置,请复制该路径。
crontab -e
Run Code Online (Sandbox Code Playgroud)
(我假设这是您的 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
Run Code Online (Sandbox Code Playgroud)
实际上您在这里所做的只是提供绝对路径