Search code examples
phplaravelcronlaravel-artisan

Laravel Artisan command launched by cron job fails without error message


I have a Laravel 9 application with some artisan commands to do some background tasks. One of these commands updates a data warehouse (update:dwh). This command runs without problems from the command line, but it fails after running for ~240 secs, if run by a cron job (see cron command below). I do not get any error message. The cron log (see below) only shows that the command failed. I also log the artisan commands to a file, but it stays empty (no error message). I suspect that the issue might be caused by the different environments (triggered by command line / cron job) and maybe by the long execution time (240 sec) or relatively high memory usage, but without any error messages, I do not know what to fix. Any ideas about how to get some meaningful error messages about the root cause of this issue? Any other hints on what can cause the command to fail?

enter image description here

Cron job log file:

2023-09-15 07:01:45 Running ['artisan' update:dwh] 
   INFO  No scheduled commands are ready to run.  


   INFO  No scheduled commands are ready to run.  


   INFO  No scheduled commands are ready to run.  


  2023-09-15 07:05:01 Running ['artisan' queue:work --stop-when-empty]  3,276ms DONE
  ⇂ '/usr/local/php82/bin/php-cli' 'artisan' queue:work --stop-when-empty >> 'storage/logs/artilog.txt' 2>&1  

.......... 241,114ms FAIL
  ⇂ '/usr/local/php82/bin/php-cli' 'artisan' update:dwh >> 'storage/logs/artilog.txt' 2>&1  


   INFO  No scheduled commands are ready to run.  


   INFO  No scheduled commands are ready to run.  


   INFO  No scheduled commands are ready to run.  


   INFO  No scheduled commands are ready to run.  

Solution

  • After multiple exchanges with my hosting company, it turned out that they have a special limitation (not part of the normal php configuration) that does not allow cron tasks to run longer than 2 minutes. I had refactor and split the cron job into multiple smaller cron-jobs and tasks and now all steps run through without any problems.