问题出现的环境背景及自己尝试过哪些方法
laravel框架中,linux环境,xshell执行crontab定时任务,
他们说的执行的项目根目录为绝对路径,我已经多方测试为绝对路径,但不知为什么还是没执行?
相关代码
// 请把代码文本粘贴到下方(请勿用图片代替代码)
<?php
namespace AppConsole;
use AppHttpControllersLogController;
use Log;
use IlluminateConsoleSchedulingSchedule;
use IlluminateFoundationConsoleKernel as ConsoleKernel;
class Kernel extends ConsoleKernel
{
/**
* The Artisan commands provided by your application.
*
* @var array
*/
protected $commands = [
\App\Console\Commands\MsgTask::class
];
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
$schedule->command('msg:send')->everyMinute();
/* $schedule->call(function () {
new LogController( 4 , "测试定时任务" );
})->everyMinute();*/
}
/**
* Register the commands for the application.
*
* @return void
*/
protected function commands()
{
$this->load(__DIR__.'/Commands');
require base_path('routes/console.php');
}
}
<?php
namespace AppConsoleCommands;
use IlluminateSupportFacadesApp;
use IlluminateConsoleCommand;
use Log;
use AppHttpControllersLogController;
class MsgTask extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'msg:send';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Msg send';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
Log::info('test');
//new LogController( 4 , "测试定时任务" );
}
}
crontab 里面的命令:
- /usr/bin/php /www/wwwroot/default/test/artisan schedule:run >> /dev/null 2>&1
先定位问题在哪里,是linux系统问题,还是crontab的问题,或者是框架的问题。