php - Laravel 4 large Route count increases booting time
We have a large web application built on Laravel 4 (4.2 currently) and we have ran into a bit of a problem. Each page load takes about 900ms just to boot up the Laravel. We did some investigation and looks that it is caused by large route count in our application - we have a list of around 1200 - 1500 routes when I launch
php artisan routes So my guess is the long load time is due the fact, that In booting process Laravel will go over all of those routes and map them... I also trieed just removing all of them and have one test route, and then the app boots up normally - in about 100 - 150ms as it should...
We have the routes spread out between many controllers in several workbench packages and also in /app/routes.php. We are using RESTful and normal controllers.
Has anyone had such a problem with a large scale application with many routes? How to solve it and not have Laravel go through all of them and map them at the booting process?
Although it's harder to maintain, you could try to separate your routes based on the first segment:
But it will make the other routes unavailable to helpers like URL::route('resource.action').
You also need to know if there's any slow code in your routes.php, like:
UPDATE: Laravel 5 has a route cache system https://mattstauffer.co/blog/laravel-5.0-route-caching