Let’s say you are running a report for the user. You generate some temporary file to give to the user and now you have this zombie pdf file sitting out there in your /tmp directory. How do you clean it up? Why not do it directly after you serve to the user? Here are a couple of options. The first option just cleans up the file after the application has served the response.
If you don’t like the idea of putting App::finish in your controller action or route closure then you could always use a helper to do your downloads. This will let you call: ResponseHelper::downloadAndDelete($filename);