RouteStatisticsBundle
About
This bundle scans your log files or the profiler data and displays an ordered
overview of the matched routes. You can use this output to optimize the order
of the routes to speed up the matching., (*1)
Installation
Append the following lines to your deps
file:, (*2)
[SecotrustRouteStatisticsBundle]
git=http://github.com/secotrust/SecotrustRouteStatisticsBundle.git
target=/bundles/Secotrust/Bundle/RouteStatisticsBundle
then run the php bin/vendors install
command., (*3)
Register the Secotrust
namespace in the autoloader:, (*4)
``` php
<?php
// app/autoload.php
$loader->registerNamespaces(array(
// ...
'Secotrust' => DIR.'/../vendor/bundles',
// ...
));, (*5)
Register the bundle in your application's kernel:
``` php
<?php
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
// ...
new Secotrust\Bundle\RouteStatisticsBundle\SecotrustRouteStatisticsBundle(),
// ...
);
...
}
Usage
The bundle adds the router:statistics
command. You can specify the --format
argument (default: profiler
) which can be one of apache
, nginx
, profiler
,
symfony
or a regular expression which extracts the method and the path info from
a log line. When you are not using the profiler
or symfony
format then you can
optionally specify a path info prefix, for example /app_dev.php
which will
be removed from the extracted path info., (*6)
The output contains the following informations:, (*7)
- Match count
- Route name
- Position of the route in the matcher class
To optimize the routing you should try to move the most used routes to the top.
Remember that the first matching route always wins., (*8)
Examples
php app/console router:statistics
21: _wdt (#11)
5: _demo (#8)
4: _configurator_step (#20)
3: _demo_secured_hello (#6)
3: _welcome (#1)
3: _demo_login (#2)
2: _demo_secured_hello_admin (#7)
2: _demo_hello (#9)
1: _configurator_final (#21)
1: _configurator_home (#19)
When using the symfony
format the command looks for lines containing
request.INFO: Matched route
., (*9)
php app/console router:statistics --format symfony app/logs/dev.log
If you want to analyze your apache or nginx log files (combined
log type)
your command should look like this:, (*10)
php app/console router:statistics --format apache /var/log/apache2/access-prod.log
Or if your log contains the front controller script name:, (*11)
php app/console router:statistics --format apache --prefix "/app_dev.php" /var/log/apache2/access-dev.log
Known issues
- Currently the output differs a bit, symfony does not always log the matched route in the app log.
- When using web server logs, the scheme is unknown.