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 launchphp 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:

$first = Request::segment(1);

if ($first === 'blog') {
    // add blog routes here
} elseif ($first === 'forum') {
    // add forum routes here

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:

Route::resource('page', slowFunctionToDecideControllerName());

UPDATE: Laravel 5 has a route cache system

People are also looking for solutions to the problem: mysql - PHP PDO HY093 error on SELECT COUNT


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.