dongwuqi4243 2016-08-26 12:41
浏览 127
已采纳

(CentOS 6)通过crontab运行Artisan命令会导致Reflection异常

When I run command php artisan schedule:run, it runs fine. However, when I put the command into the scheduler as follows:

* * * * * php /PATH/TO/PROJECT/artisan schedule:run >> /PATH/TO/PROJECT/storage/logs/scheduler.log 2>&1

I get the following error every time it runs.

PHP Fatal error:  Uncaught ReflectionException: Class log does not exist ...

This question shows that it's because of an error that happens early in the bootstrap process and tries to log an error before the logger is registered.

I can't seem to figure out where to start debugging since this is the only call stack I get:

PHP Fatal error:  Uncaught ReflectionException: Class log does not exist in /PATH/TO/PROJECT/vendor/laravel/framework/src/Illuminate/Container/Container.php:734
Stack trace:
#0 /PATH/TO/PROJECT/vendor/laravel/framework/src/Illuminate/Container/Container.php(734): ReflectionClass->__construct('log')
#1 /PATH/TO/PROJECT/vendor/laravel/framework/src/Illuminate/Container/Container.php(629): Illuminate\Container\Container->build('log', Array)
#2 /PATH/TO/PROJECT/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(697): Illuminate\Container\Container->make('log', Array)
#3 /PATH/TO/PROJECT/vendor/laravel/framework/src/Illuminate/Container/Container.php(849): Illuminate\Foundation\Application->make('log')
#4 /PATH/TO/PROJECT/vendor/laravel/framework/src/Illuminate/Container/Container.php(804): Illuminate\Container\Container->resolveClass(Object(ReflectionParameter))
#5 /PATH/TO/PROJECT/vendor/laravel/framework/src/Illuminate/Container/Container.php(773): Illuminate\Container\Container in /PATH/TO/PROJECT/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 734

I suspect it may have something to do with permissions, however the crontab is tied to the same user who runs it manually. What is causing the original error?

  • 写回答

1条回答 默认 最新

  • duanmu1736 2016-09-08 09:46
    关注

    I've found what was causing my error in particular (it may/may not vary for others). After debugging through many source files I've found the source of the issue was that the PDO extension wasn't being loaded. I don't know why this was the case only when running as a cron-job.

    As a note: it seems that other having the same issue often have it during the configuration phase so it might be a good idea to start debugging from there if you are getting the same exception.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?