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?
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.
Related
This is on MacOS with PHP 8.1.10 installed via homebrew ...
Just a blank index.php code in it with only this code ...
<?php
die('We Should Just Die Here');
throw new \RuntimeException('This exception should never be seen');
?>
And .. render in my browser to see ...
<br />
<b>Fatal error</b>: Uncaught RuntimeException: This exception should never be seen in /path/to/public/index.php:4
Stack trace:
#0 /Users/my-user/.composer/vendor/laravel/valet/server.php(234): require()
#1 {main}
thrown in <b>/path/to/public/index.php</b> on line <b>4</b><br />
Same story if I run it command line (taking valet out of the equation) ..
$ php index.php
Fatal error: Uncaught RuntimeException: This exception should never be seen in /path/to/public/index.php:4
Stack trace:
#0 {main}
thrown in /path/to/public/index.php on line 4
I have already tried ...
Upgrading PHP
Re-installed Valet
Composer updating everything
In my roughly 800 years of writing PHP code I have never seen anything like this. Please if anyone has any help I'm interested.
I've found it. I installed the php-uopz extension a while back. I had completely forgotten about that.
pecl uninstall uopz fixed this for me.
Thank you for the rubber ducking stack overflow ;P
I executed git reset --hard, but now I get:
PHP Fatal error: Uncaught Error: Class 'Magento\Setup\Application' not found in /home/xy/vendor/magento/framework/Console/Cli.php:79
Stack trace:
#0 /home/xy/bin/magento(22): Magento\Framework\Console\Cli->__construct('Magento CLI')
#1 {main}
thrown in /home/xy/vendor/magento/framework/Console/Cli.php on line 79
I executed composer update in hope that this fixes it, but it doesnt. How can I fix?
It turned out that git reset --hard destroyed my setup folder for unknown reasons and not even git pull fixed it.
So I had to copy the folder from another project. Now it works.
I just run git reset --hard again and that fixed the issue.
I am working through upgrading my PHP 5.4, Laravel 4.2 application to PHP 7.4, Laravel 5.8.
In some of my tests, on tearDownAfterClass, I will do some DB cleanup. With Laravel 5.8, these don't work and I can't figure out why.
The following test using Laravel 5.4, works. With 5.8, does not work.
I have updated my 5.8 configs from the defaults, they are proper.
My database connection works, the tests all pass with DB activity.
The error only fails in the static tearDownAfterClass, I added the same \DB::table(static::$audittable)->truncate(); to one of my tests, it works without error.
How do I fix the exception below?
Using PHP 7.4.6, Laravel 5.8:
class ModelAuditQueriesTest extends TestCase
{
static $audittable = 'contactnotesaudit';
public static function tearDownAfterClass()
{
\DB::table(static::$audittable)->truncate(); **// <-- this fails, error below; line 11**
parent::tearDownAfterClass();
}
public function testInsertSingle()
{
\DB::table(static::$audittable)->truncate(); **// <-- this works, no errors**
/**
* testing stuff with models that insert and select with database, successfully
*/
}
}
With PHPUNIT.XML, processIsolation = false
PHP Fatal error: Uncaught Illuminate\Contracts\Container\BindingResolutionException: Target [Illuminate\Contracts\Debug\ExceptionHandler] is not instantiable. in C:\CODE\IDWEB5\vendor\laravel\framework\src\Illuminate\Container\Container.php:960
Stack trace:
#0 C:\CODE\IDWEB5\vendor\laravel\framework\src\Illuminate\Container\Container.php(794): Illuminate\Container\Container->notInstantiable('Illuminate\\Cont...')
#1 C:\CODE\IDWEB5\vendor\laravel\framework\src\Illuminate\Container\Container.php(667): Illuminate\Container\Container->build('Illuminate\\Cont...')
#2 C:\CODE\IDWEB5\vendor\laravel\framework\src\Illuminate\Container\Container.php(615): Illuminate\Container\Container->resolve('Illuminate\\Cont...', Array)
#3 C:\CODE\IDWEB5\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(767): Illuminate\Container\Container->make('Illuminate\\Cont...', Array)
#4 C:\CODE\IDWEB5\vendor\laravel\framework\src\Illuminate\Foundation\Bootstrap\HandleExceptions.php(170): Illuminate\Foundation\Application->make('Illuminate\\ in C:\CODE\IDWEB5\vendor\laravel\framework\src\Illuminate\Container\Container.php on line 960
PHP Fatal error: Uncaught Illuminate\Contracts\Container\BindingResolutionException: Target [Illuminate\Contracts\Debug\ExceptionHandler] is not instantiable. in C:\CODE\IDWEB5\vendor\laravel\framework\src\Illuminate\Container\Container.php:960
Stack trace:
#0 C:\CODE\IDWEB5\vendor\laravel\framework\src\Illuminate\Container\Container.php(794): Illuminate\Container\Container->notInstantiable('Illuminate\\Cont...')
#1 C:\CODE\IDWEB5\vendor\laravel\framework\src\Illuminate\Container\Container.php(667): Illuminate\Container\Container->build('Illuminate\\Cont...')
#2 C:\CODE\IDWEB5\vendor\laravel\framework\src\Illuminate\Container\Container.php(615): Illuminate\Container\Container->resolve('Illuminate\\Cont...', Array)
#3 C:\CODE\IDWEB5\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(767): Illuminate\Container\Container->make('Illuminate\\Cont...', Array)
#4 C:\CODE\IDWEB5\vendor\laravel\framework\src\Illuminate\Foundation\Bootstrap\HandleExceptions.php(170): Illuminate\Foundation\Application->make('Illuminate\\ in C:\CODE\IDWEB5\vendor\laravel\framework\src\Illuminate\Container\Container.php on line 960
With PHPUNIT.XML, processIsolation = true
PHP Fatal error: Uncaught Error: Class 'DB' not found in C:\CODE\IDWEB5\tests\commonmodelaudit\ModelAuditQueriesTest.php:11
Stack trace:
#0 C:\CODE\IDWEB5\vendor\phpunit\phpunit\src\Framework\TestSuite.php(760): Tests\commonmodelaudit\ModelAuditQueriesTest::tearDownAfterClass()
#1 C:\CODE\IDWEB5\vendor\phpunit\phpunit\src\TextUI\TestRunner.php(545): PHPUnit\Framework\TestSuite->run(Object(PHPUnit\Framework\TestResult))
#2 C:\CODE\IDWEB5\vendor\phpunit\phpunit\src\TextUI\Command.php(195): PHPUnit\TextUI\TestRunner->doRun(Object(PHPUnit\Framework\TestSuite), Array, true)
#3 C:\CODE\IDWEB5\vendor\phpunit\phpunit\src\TextUI\Command.php(148): PHPUnit\TextUI\Command->run(Array, true)
#4 C:\CODE\IDWEB5\vendor\phpunit\phpunit\phpunit(53): PHPUnit\TextUI\Command::main()
#5 {main}
thrown in C:\CODE\IDWEB5\tests\commonmodelaudit\ModelAuditQueriesTest.php on line 11
Error : Cannot use object of type Illuminate\Support\Facades\Config as array
C:\CODE\IDWEB5\vendor\laravel\framework\src\Illuminate\Database\DatabaseManager.php:270
C:\CODE\IDWEB5\vendor\laravel\framework\src\Illuminate\Database\DatabaseManager.php:101
C:\CODE\IDWEB5\vendor\laravel\framework\src\Illuminate\Database\DatabaseManager.php:77
C:\CODE\IDWEB5\vendor\laravel\framework\src\Illuminate\Database\DatabaseManager.php:349
C:\CODE\IDWEB5\vendor\laravel\framework\src\Illuminate\Support\Facades\Facade.php:239
C:\CODE\IDWEB5\tests\commonmodelaudit\ModelAuditQueriesTest.php:11
I have run the following to make sure all is clean:
composer dump-autoload
php artisan clear-compiled
php artisan optimize
php artisan cache:clear
php artisan config:clear
php artisan route:clear
php artisan view:clear
I think the application has already shut down at the tearDownAfterClass part of the code.
Since you are trying to truncate a table, I think you might find it easier to instead use the trait DatabaseTransactions e.g.
class ModelAuditQueriesTest extends TestCase
{
use DatabaseTransactions;
}
this will make any changes you make in the database during this test not be rolled back since they are all done within a transaction which is never committed.
Another hacky way to do what you want is to "restart" the application.
The TestCase that comes in the boilerplate has a trait CreatesApplication. This unfortunately is not static but you can just copy-paste it and "restart" the application:
class ModelAuditQueriesTest extends TestCase
{
static $audittable = 'contactnotesaudit';
public static function tearDownAfterClass()
{
$app = require __DIR__.'/../bootstrap/app.php'; //You might need to adjust the path
$app->make(Kernel::class)->bootstrap();
\DB::table(static::$audittable)->truncate();
parent::tearDownAfterClass();
}
}
Now unfortunately the error you are seeing is that the error handler could not be instantiated which means once you do this you will see the actual reason that the error handler was being instantiated which is probably going to be another exception. However, at least that might be more informative.
I've been stuck trying to figure out why I get this every time I try to run php artisan key:generate (or any other php artisan command).
PHP Fatal error: Uncaught ReflectionException: Class log does not exist in C:\Users\Sam\PhpstormProjects\banqo.net\vendor\laravel\framework\src\Illuminate\Container\Container.php:734
Stack trace:
#0 C:\Users\Sam\PhpstormProjects\banqo.net\vendor\laravel\framework\src\Illuminate\Container\Container.php(734): ReflectionClass->__construct('log')
#1 C:\Users\Sam\PhpstormProjects\banqo.net\vendor\laravel\framework\src\Illuminate\Container\Container.php(629): Illuminate\Container\Container->build('log', Array)
#2 C:\Users\Sam\PhpstormProjects\banqo.net\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(697): Illuminate\Container\Container->make('log', Array)
#3 C:\Users\Sam\PhpstormProjects\banqo.net\vendor\laravel\framework\src\Illuminate\Container\Container.php(849): Illuminate\Foundation\Application->make('log')
#4 C:\Users\Sam\PhpstormProjects\banqo.net\vendor\laravel\framework\src\Illuminate\Container\Container.php(804): Illuminate\Container\Container->resolveClass(Object(ReflectionParameter))
#5 C:\Users\Sam\P in C:\Users\Sam\PhpstormProjects\banqo.net\vendor\laravel\framework\src\Illuminate\Container\Container.php on line 734
Fatal error: Uncaught ReflectionException: Class log does not exist in C:\Users\Sam\PhpstormProjects\banqo.net\vendor\laravel\framework\src\Illuminate\Container\Container.php:734
Stack trace:
#0 C:\Users\Sam\PhpstormProjects\banqo.net\vendor\laravel\framework\src\Illuminate\Container\Container.php(734): ReflectionClass->__construct('log')
#1 C:\Users\Sam\PhpstormProjects\banqo.net\vendor\laravel\framework\src\Illuminate\Container\Container.php(629): Illuminate\Container\Container->build('log', Array)
#2 C:\Users\Sam\PhpstormProjects\banqo.net\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(697): Illuminate\Container\Container->make('log', Array)
#3 C:\Users\Sam\PhpstormProjects\banqo.net\vendor\laravel\framework\src\Illuminate\Container\Container.php(849): Illuminate\Foundation\Application->make('log')
#4 C:\Users\Sam\PhpstormProjects\banqo.net\vendor\laravel\framework\src\Illuminate\Container\Container.php(804): Illuminate\Container\Container->resolveClass(Object(ReflectionParameter))
#5 C:\Users\Sam\P in C:\Users\Sam\PhpstormProjects\banqo.net\vendor\laravel\framework\src\Illuminate\Container\Container.php on line 734
Some suggested putting this at the top of vendor\laravel\framework\src\Illuminate\Container\Container.php because it would reveal the underlying error:
namespace {
use Monolog\Logger as Monolog;
class log extends Illuminate\Log\Writer {
function __construct()
{
$this->monolog = new Monolog("local");
}
}
}
But instead I started getting:
PHP Fatal error: Uncaught ReflectionException: Class env does not exist in C:\Users\Sam\PhpstormProjects\banqo.net\vendor\laravel\
framework\src\Illuminate\Container\Container.php:744
with a similar stacktrace to the initial error. I've been researching online what could be causing it. Someone suggested running 'phpunit', so I did and I got the error:
Dotenv\Exception\InvalidFileException: Dotenv values containing spaces must be surrounded by quotes.
I thought this was interesting because people had suggested that .env values containing spaces could have caused the initial problem, but I have thoroughly and repeatedly checked my .env file for spaces and there are none where there shouldn't be. I even tried wrapping literally every single .env value in quotes. On top of all this my IDE (Phpstorm) tells me that there are no errors in any of the files in my config folder.
What could be causing this issue?
STEP 1
Make sure you have installed all packages properly composer install.
STEP 2
Run composer dump-autoload to generate class references again.
I just took a project from a couple of months ago which was made in Laravel. This project also utilizes Laravel Voyager - the admin panel package.
After browsing to http://example.com/admin, I got this weird error which came out of nowhere and I'm also unsure how to debug it. It looks like this:
Fatal error: Cannot declare class Symfony\Component\HttpFoundation\AcceptHeader, because the name is already in use in /c/Users/User/Code/example-website/vendor/symfony/http-foundation/AcceptHeader.php on line 22
Fatal error: Uncaught Error: Class 'Symfony\Component\HttpFoundation\AcceptHeaderItem' not found in /c/Users/User/Code/example-website/vendor/symfony/http-foundation/AcceptHeader.php:61 Stack trace: #0 [internal function]: Symfony\Component\HttpFoundation\AcceptHeader::Symfony\Component\HttpFoundation\{closure}(Array) #1 /c/Users/User/Code/example-website/vendor/symfony/http-foundation/AcceptHeader.php(57): array_map(Object(Closure), Array) #2 /c/Users/User/Code/example-website/vendor/symfony/http-foundation/Request.php(1664): Symfony\Component\HttpFoundation\AcceptHeader::fromString('text/html,appli...') #3 /c/Users/User/Code/example-website/vendor/laravel/framework/src/Illuminate/Http/Concerns/InteractsWithContentTypes.php(54): Symfony\Component\HttpFoundation\Request->getAcceptableContentTypes() #4 /c/Users/User/Code/example-website/vendor/laravel/framework/src/Illuminate/Http/Concerns/InteractsWithContentTypes.php(44): Illuminate\Http\Request->wantsJson() #5 /c/Users/User/Code/example-website/vendor/laravel/framework/src/Illumina in /c/Users/User/Code/example-website/vendor/symfony/http-foundation/AcceptHeader.php on line 61
This error is very expected and I've never seen it before in my project (or anywhere else for that matter).
How can I debug this issue?
As a sanity check, delete the vendor directory and then run composer install to re-fetch your dependencies and see if the error is resolved. If not, then attempt composer update to fetch the latest versions of your dependencies in which this issue may have been resolved.