laravel,linux,xshell执行crontab定时任务,定时任务日志执行正常,但laravel中的日志写入并未执行?

图片描述

问题出现的环境背景及自己尝试过哪些方法

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

你期待的结果是什么?实际看到的错误信息又是什么?

阅读 3.8k
2 个回答

先定位问题在哪里,是linux系统问题,还是crontab的问题,或者是框架的问题。

新手上路,请多包涵

已解决,为php路径的问题,和php.ini的配置问题

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题