Laravel计划任务和cron任务

huangapple go评论60阅读模式
英文:

Laravel schedule and cron task

问题

我已定义了一个在我的Laravel应用程序中的计划任务命令,并且已经配置了每分钟运行的cron任务:php public_html/laravel/artisan schedule:run

但是,当执行cron任务时,我收到以下信息:

Laravel Framework 9.46.0

Usage:
  command [options] [arguments]

Options:
  -h, --help            Display help for the given command. When no command is given display help for the list command
  -q, --quiet           Do not output any message
  -V, --version         Display this application version
      --ansi|--no-ansi  Force (or disable --no-ansi) ANSI output
  -n, --no-interaction  Do not ask any interactive question
      --env[=ENV]       The environment the command should run under
  -v|vv|vvv, --verbose  Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Available commands:
  about                         Display basic information about your application
  clear-compiled                Remove the compiled class file
  completion                    Dump the shell completion script
  db                            Start a new database CLI session
  docs                          Access the Laravel documentation
  down                          Put the application into maintenance / demo mode
  env                           Display the current framework environment
  help                          Display help for a command
  inspire                       Display an inspiring quote
  list                          List commands
  migrate                       Run the database migrations
  optimize                      Cache the framework bootstrap files
  serve                         Serve the application on the PHP development server
  tinker                        Interact with your application
  up                            Bring the application out of maintenance mode
 auth
  auth:clear-resets             Flush expired password reset tokens
 cache
  cache:clear                   Flush the application cache
  cache:forget                  Remove an item from the cache
  cache:table                   Create a migration for the cache database table
 config
  config:cache                  Create a cache file for faster configuration loading
  config:clear                  Remove the configuration cache file
 db
  db:monitor                    Monitor the number of connections on the specified database
  db:seed                       Seed the database with records
  db:show                       Display information about the given database
  db:table                      Display information about the given 

X-Powered-By: PHP/8.1.18
Content-type: text/html; charset=UTF-8

我不明白为什么命令没有执行。有人可以帮我吗?

英文:

I have define, a schedule command in my Laravel application and I have configure this cron task every minute : php public_html/laravel/artisan schedule:run

but when the cron task is execute I receive this :

Laravel Framework 9.46.0

Usage:
  command [options] [arguments]

Options:
  -h, --help            Display help for the given command. When no command is given display help for the list command
  -q, --quiet           Do not output any message
  -V, --version         Display this application version
      --ansi|--no-ansi  Force (or disable --no-ansi) ANSI output
  -n, --no-interaction  Do not ask any interactive question
      --env[=ENV]       The environment the command should run under
  -v|vv|vvv, --verbose  Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Available commands:
  about                         Display basic information about your application
  clear-compiled                Remove the compiled class file
  completion                    Dump the shell completion script
  db                            Start a new database CLI session
  docs                          Access the Laravel documentation
  down                          Put the application into maintenance / demo mode
  env                           Display the current framework environment
  help                          Display help for a command
  inspire                       Display an inspiring quote
  list                          List commands
  migrate                       Run the database migrations
  optimize                      Cache the framework bootstrap files
  serve                         Serve the application on the PHP development server
  tinker                        Interact with your application
  up                            Bring the application out of maintenance mode
 auth
  auth:clear-resets             Flush expired password reset tokens
 cache
  cache:clear                   Flush the application cache
  cache:forget                  Remove an item from the cache
  cache:table                   Create a migration for the cache database table
 config
  config:cache                  Create a cache file for faster configuration loading
  config:clear                  Remove the configuration cache file
 db
  db:monitor                    Monitor the number of connections on the specified database
  db:seed                       Seed the database with records
  db:show                       Display information about the given database
  db:table                      Display information about the given 

X-Powered-By: PHP/8.1.18
Content-type: text/html; charset=UTF-8

I don't understand why the command is not execute. Someone can help me please Laravel计划任务和cron任务

答案1

得分: 0

将cron表达式添加以指定cron应该多久运行一次(在这种情况下,每分钟运行一次):

英文:

Add a cron expression to specify how often the cron should run (in this case every minute):

* * * * * php /home/user/public_html/laravel/artisan schedule:run >> /dev/null 2>&1

The above entry will run and specify the logs on standard output (console); however you can also put the logs into storage for debugging:

* * * * * php /home/user/public_html/laravel/artisan schedule:run >> /home/user/public_html/laravel/storage/cron.log

P.S: Make sure you're using correct (absolute) public path.

huangapple
  • 本文由 发表于 2023年5月17日 17:51:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/76270770.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定