title: PHP Symfony2: Delete a temp file after response
body: <p>I have a controller that generates an image and returns the image in the response. </p>
  
  <pre><code>use FOS\RestBundle\Controller\Annotations as Rest;
  use Symfony\Component\HttpFoundation\BinaryFileResponse;
  
  ...
  
  /**
   * @Rest\Get("/image/{name}")
   */
  public function getImage($name) {
      $imageService = $this-&gt;get('image.service');
      $tempImage = $imageService-&gt;genImage($name);
      return new BinaryFileResponse($tempImage);
  }
  </code></pre>
  
  <p>This works great but temp image never gets deleted. </p>
  
  <p>How do I delete the temp image after the response is sent?</p>