When a service provider is already in the compiled and you attempt to php artisan clear-compiled it will error. This is because Laravel needs to bootstrap before it can even run the command. This makes the command quite unreliable and a bit flawed as it cannot be used when you have removed a service provider.
Maybe the command could somehow be a stand-alone thing and not require bootstrapping of Laravel in order to run? @taylorotwell
Thanks for reporting @garygreen, but we already know about this, and I already suggested we change this to be stand alone, but Taylor didn't like the idea. The best work around is for you to just do something like this: https://github.com/StyleCI/StyleCI/blob/master/composer.json#L67.
Thanks @GrahamCampbell. It's a pretty simple fix really, suprised Taylor didn't like the idea as the command is pretty flawed imo.
I've decided to implement it a slightly different way than you suggested so that's it's both Windows/Unix friendly by having a clear-compiled file alongside artisan in my base directory.
Instructions below just in case anyone else stumbles across this and would like the clear-compiled command to always work! :smile:
clear-compiled
#!/usr/bin/env php
<?php
foreach (glob(__DIR__ . '/bootstrap/cache/*.*') as $file) {
@unlink($file);
}
echo 'Cleared compiled directory.';
exit();
Then in composer.json change php artisan clear-compiled to simply php clear-compiled
"scripts": {
"pre-install-cmd": [
"php clear-compiled"
],
"post-install-cmd": [
"php clear-compiled"
]
},
I've created a repository for this in case anyone would like to use the standalone clear-compiled command in their app :+1:
@GrahamCampbell have you at least tested that rm command?
rm is not supposed to work like that, you have to tell which folders you want to remove:
rm -f bootstrap/cache/compiled.php bootstrap/cache/config.php bootstrap/cache/routes.php bootstrap/cache/services.json
or use find to delete some files
find bootstrap/ -type f -name "compiled.php" -exec rm -f {} \;
find bootstrap/ -type f -name "routes.php" -exec rm -f {} \;
find bootstrap/ -type f -name "services.json" -exec rm -f {} \;
if you don`t want to delete them all:
rm -f bootstrap/cache/*
This last command will not delete the .gitinore file.
@antonioribeiro I did think those commands @GrahamCampbell posted example of was weird and thought you should tell it the paths as well... but in any case I think rm is not a good option because it isn't available on Windows (unless thru Cygwin or something). Using this script is more reliable for cross OS and keeps it pretty much identical in usage to the php artisan clear-compiled vs just php clear-compiled.
@GrahamCampbell have you at least tested that rm command?
Yeh. I use it in production...
Ok, I've made a new issue for this: https://github.com/laravel/framework/issues/9678.
Most helpful comment
Thanks @GrahamCampbell. It's a pretty simple fix really, suprised Taylor didn't like the idea as the command is pretty flawed imo.
I've decided to implement it a slightly different way than you suggested so that's it's both Windows/Unix friendly by having a
clear-compiledfile alongsideartisanin my base directory.Instructions below just in case anyone else stumbles across this and would like the clear-compiled command to always work! :smile:
clear-compiled
Then in
composer.jsonchangephp artisan clear-compiledto simplyphp clear-compiled