Laravel artisan route:cache causes Erroneous data Exception Running the command: php artisan route:cache produces the following execption:
Erroneous data format for unserializing 'Symfony\Component\Routing\CompiledRoute'
Running: php artisan route:clear fixes it
I'd like to know how I can fix this so I can cache my routes.
If you had closures in your routes you will get errors while caching, but the error message is different then.
If you don't want to share the routes file, then I would suggest that you add bunch of routes, and comment the rest, try caching and do that until the end, until you find out which route causes the issue, and share it here, so you could get better help.
Also share which version of PHP and Laravel are you running.
Hi Nakov,
I should mention that I have pulled from a working branch and everything is caching perfectly on my other machine. I have 0 closures in my routes.
PHP ver: 7.4.1
Laravel ver: 6.X
@nathand19 have you tried my other suggestion? Commenting out most of the routes and trying to cache couple of them just to see if the error exists no matter what, or is there any particular route that causes this issue?
Yep, commented all routes except for one (tried with multiple).
I believe the error is appearing no matter what.
From the logs:
[2019-12-27 09:14:12] local.ERROR: Erroneous data format for unserializing 'Symfony\Component\Routing\CompiledRoute' {"exception":"[object] (ErrorException(code: 0): Erroneous data format for unserializing 'Symfony\\Component\\Routing\\CompiledRoute' at /var/www/GhandaHub/bootstrap/cache/routes.php:15) [stacktrace] #0 [internal function]: Illuminate\\Foundation\\Bootstrap\\HandleExceptions->handleError(2, 'Erroneous data ...', '/var/www/Ghanda...', 15, Array) #1 /var/www/GhandaHub/bootstrap/cache/routes.php(15): unserialize('O:34:\"Illuminat...') #2 /var/www/GhandaHub/vendor/laravel/framework/src/Illuminate/Foundation/Support/Providers/RouteServiceProvider.php(75): require('/var/www/Ghanda...') #3 /var/www/GhandaHub/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(868): Illuminate\\Foundation\\Support\\Providers\\RouteServiceProvider->Illuminate\\Foundation\\Support\\Providers\\{closure}(Object(Illuminate\\Foundation\\Application)) #4 /var/www/GhandaHub/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(817): Illuminate\\Foundation\\Application->fireAppCallbacks(Array) #5 /var/www/GhandaHub/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/BootProviders.php(17): Illuminate\\Foundation\\Application->boot() #6 /var/www/GhandaHub/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(212): Illuminate\\Foundation\\Bootstrap\\BootProviders->bootstrap(Object(Illuminate\\Foundation\\Application)) #7 /var/www/GhandaHub/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(156): Illuminate\\Foundation\\Application->bootstrapWith(Array) #8 /var/www/GhandaHub/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(140): Illuminate\\Foundation\\Http\\Kernel->bootstrap() #9 /var/www/GhandaHub/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(110): Illuminate\\Foundation\\Http\\Kernel->sendRequestThroughRouter(Object(Illuminate\\Http\\Request)) #10 /var/www/GhandaHub/public/index.php(55): Illuminate\\Foundation\\Http\\Kernel->handle(Object(Illuminate\\Http\\Request)) #11 {main} "}
@nathand19 did you checkout the project from a Git repo on your other machine? Did you by any chance have transferred other cached files from before?
Tried:
php artisan cache:clear
?
or even
composer update
in case the problem is within the symfony library and now it is fixed? Really hard to find any other tracks on this issue happening to someone else :)
php artisan cache:clear does fix the issue, but then routes are not cached.
All dependencies are up to date too. I may just reclone and try again.
No cache files were copied, all from git repo which just holds source code.
I also have this exact problem...
I deleted all of my routes for both web and api, and have only 1 route remaining, which is:
Route::get('/', 'HomeController@home');
But after cache:clear and route:cache, the error is still there... (it is gone after I run route:clear , but then my routes are not cached!)
ErrorException
Erroneous data format for unserializing 'Symfony\Component\Routing\CompiledRoute'
Laravel Framework 6.9.0
I just had the same issue, I fixed it removing the vendor folder and running composer install again. Also had to remove the cache files using rm -fr bootstrap/cache/*. Dirty but worked.
@davidvexel tried removing cache files, that worked, but recaching them causes the same error
FWIW, I am having the same problem with Vapor deployments. It doesn't exist locally but is borked once it gets deployed on Vapor.
I didn't have closures in my routes; and I get this issue. I add a closure and the issue goes away.
facing the same issue. route:cache on local does not show any error but facing issue in production.
I have found out that downgrading sympony/routing package to v4.2.0 helped.
Steps to solve it:
-composer require symfony/routing:v4.2.0
-Remove routes.php content
-php artisan route:cache
Let me know if it is working for you
run artisan route:list and see if you have any routes added by packages.
Yep seems like something is messing route:list command
I will dig a little bit more in the docs to see if there is any solution
After downgrading to symfony/routing:v4.2.0 i have tried to run route:list and it did not work.
That was because i had some missing class in my web.php
after removing it, resetting routes.php content.
every thing is now working.
This still occurs after updating to Laravel 6.11...
ErrorException
Erroneous data format for unserializing 'Symfony\Component\Routing\CompiledRoute'
If any one finds a solution, please kindly share.
Have you tried downgrading symfony/routing to v4.2.0?
Yeah, but received this error (Laravel 6.11 requires at least symfony/routing 4.3.4): "Your requirements could not be resolved to an installable set of packages."
I installed symfony/routing 4.4.x-dev to see if that fixes it... but issue still persists!
Unfortunately, I cant downgrade to symfony/routing to v4.2.0.
Same problem as @imbee
If anyone still has this issue,
Apparently PHP 7.3 cannot read Laravel cached routes from PHP 7.4
It was fixed when I used the same version of PHP on both CLI and server.
If anyone still has this issue, Apparently PHP 7.3 cannot read Laravel cached routes from PHP 7.4
It was fixed when I used the same version of PHP on both CLI and server.
Thank you, it really helped!
I resolved it next way:
!!! remove file /bootstrap/cache/routes.php
composer require symfony/routing:v4.2.0
php artisan route:cache
profit!
@kib -ev Worked for me! Thank you
@kib -ev solved, thank you!
When I run composer require symfony/routing:v4.2.0, I recieve this error:
Problem 1
- laravel/framework v6.9.0 requires symfony/routing ^4.3.4 -> satisfiable by symfony/routing[4.3.x-dev, 4.4.x-dev].
- laravel/framework v6.9.0 requires symfony/routing ^4.3.4 -> satisfiable by symfony/routing[4.3.x-dev, 4.4.x-dev].
- laravel/framework v6.9.0 requires symfony/routing ^4.3.4 -> satisfiable by symfony/routing[4.3.x-dev, 4.4.x-dev].
- Can only install one of: symfony/routing[v4.2.0, 4.3.x-dev].
- Can only install one of: symfony/routing[v4.2.0, 4.4.x-dev].
- Installation request for symfony/routing v4.2.0 -> satisfiable by symfony/routing[v4.2.0].
- Installation request for laravel/framework v6.9.0 -> satisfiable by laravel/framework[v6.9.0].
After a bunch of troubleshooting, uninstalling all php versions except 7.4.2 then reconfiguring apache2 server fixed it.
Although it's late, it can be still helpful if someone facing the same issue.
It's simple to resolve this issue. Just delete the file bootstrap\cache\routes-v7.php and run the command "php artisan optimize".
That's it.
Please sign in or create an account to participate in this conversation.