With the event listener below, we're going to see what actions cause master and sub requests throughout the system. I've listed some of them below but I guess this list can be extended more.


Request types


Master


External requests that directly come from the user action.



Sub


Internal requests that does not come from the user action.



Parameters.yml


parameters:
listener.log.file: '%kernel.logs_dir%/listener.log'

# football/app/logs/listener.log

Listeners.yml


services:
application_backend.listener.user_controller:
class: Application\BackendBundle\EventListener\UserControllerListener
arguments:
- %listener.log.file%
tags:
- { name: kernel.event_listener, event: kernel.request, method: onKernelRequest }

UserControllerListener.php


namespace Application\BackendBundle\EventListener;

use Symfony\Component\HttpKernel\Event\GetResponseEvent;

class UserControllerListener
{
private $logFile;
private $message = [
true => 'Master request',
false => 'Sub request'
];

public function __construct($logFile)
{
$this->logFile = $logFile;
}

public function onKernelRequest(GetResponseEvent $event)
{
$this->logRequest(
$this->message[$event->isMasterRequest()],
$event->getRequest()->getMethod()
);
}

private function logRequest($message, $method = null)
{
file_put_contents(
$this->logFile,
file_exists($this->logFile)
? file_get_contents($this->logFile) . "\n" . $method . ':' . $message
: $method . ':' . $message
);
}
}

Listener.log


GET:Master request
GET:Sub request
GET:Master request
POST:Master request
GET:Master request
GET:Sub request
GET:Sub request
GET:Master request
GET:Master request
GET:Sub request
GET:Master request