Batch requests on Symfony
<p>I am trying to reproduce the behaviour of the <a href="https://developers.facebook.com/docs/graph-api/making-multiple-requests" rel="noreferrer">facebook batch requests</a> function on their graph api. </p>

<p>So I think that the easiest solution is to make several requests on a controller to my application like: </p>

<pre><code>public function batchAction (Request $request)
{
    $requests = $request-&gt;all();
    $responses = [];

    foreach ($requests as $req) {
        $response = $this-&gt;get('some_http_client')
            -&gt;request($req['method'],$req['relative_url'],$req['options']);

        $responses[] = [
            'method' =&gt; $req['method'],
            'url' =&gt; $req['url'],
            'code' =&gt; $response-&gt;getCode(),
            'headers' =&gt; $response-&gt;getHeaders(),
            'body' =&gt; $response-&gt;getContent()
        ]
    }

    return new JsonResponse($responses)
}
</code></pre>

<p>So with this solution, I think that my functional tests would be green. </p>

<p>However, I fill like initializing the service container X times might make the application much slower. Because for each request, every bundle is built, the service container is rebuilt each time etc... </p>

<p>Do you see any other solution for my problem? </p>

<p><strong>In other words, do I need to make complete new HTTP requests to my server to get responses from other controllers in my application?</strong> </p>

<p>Thank you in advance for your advices!</p>