You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Laravel定时任务无法运行:执行schedule:run提示无待执行命令

解决Laravel调度任务提示"No scheduled commands are ready to run"的问题

按照以下步骤逐一排查修复:

  • 确认自定义命令存在且可独立运行
    你调度的command:email:daily必须是已创建并注册的合法Artisan命令:

    1. 执行php artisan make:command EmailDailyCommand生成命令文件
    2. 在app/Console/Commands/EmailDailyCommand.php中设置protected $signature = 'command:email:daily';,并在handle()方法中编写具体任务逻辑
    3. 单独执行php artisan command:email:daily,确认命令能正常运行无报错
  • 检查调度配置的位置合法性

    • 若使用Laravel 10+,你在routes/console.php中的代码格式没问题;若为旧版本,需将调度代码移至app/Console/Kernel.php的schedule()方法中:
      protected function schedule(Schedule $schedule)
      {
          $schedule->command('command:email:daily')->everyMinute();
      }
      
  • 配置系统Cron实现自动调度
    手动执行php artisan schedule:run仅能触发一次任务,要实现每分钟自动运行,需在服务器Cron中添加定时任务:

    1. 执行crontab -e编辑Cron任务列表
    2. 添加以下内容(替换/path-to-your-project为你的项目根目录绝对路径):
      * * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1
      
    3. 若服务器无法全局调用PHP,用which php查看完整PHP路径,替换命令中的php,例如:
      * * * * * cd /path-to-your-project && /usr/bin/php artisan schedule:run >> /dev/null 2>&1
      
  • 额外排查项

    • 时区验证:确保.env文件中APP_TIMEZONE设置正确(如APP_TIMEZONE=Asia/Shanghai),时区错误会导致调度时间判断偏差
    • 日志排查:给任务添加日志输出,验证是否执行:
      $schedule->command('command:email:daily')->everyMinute()->appendOutputTo(storage_path('logs/schedule.log'));
      
      等待一分钟后查看storage/logs/schedule.log是否有内容

内容的提问来源于stack exchange,提问作者masteryoda

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.12 19:07:17