Search code examples
laravelcrontask

Laravel schedule and cron task


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 :)


Solution

  • 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.