Wow, long time no blog post, huh? Here’s a quick tip how to stream a (presumably large) file to your client with Symfony without the need to load the file into memory.

<?php
$file   = '/tmp/a-large-file.jpg';
$format = pathinfo($file, PATHINFO_EXTENSION);

return new \Symfony\Component\HttpFoundation\StreamedResponse(
    function () use ($file) {
        readfile($file);
    }, 200, array('Content-Type' => 'image/' . $format)
);

Sources