Reputation: 40685
Is it possible that the creation of a rather largge (20MB) .csv download creates a memory leak in case the user stops the download/export before the file has been saved on his machine?
If yes, how would you catch and counter this problem?
Upvotes: 1
Views: 192
Reputation: 5231
If you are generating the file on the fly and streaming it to the user you may want to look at http://php.net/manual/en/features.connection-handling.php and perform some cleanup if the connection gets aborted or times out.
Upvotes: 1
Reputation: 239860
It's possible but I would imagine it would get cleared up eventually. Either way, HTTPds are generally a lot more efficient at serving files than a server side language.
If you're worried, save the file (I assume we're talking about a dynamically generated file) to the filesystem (somewhere where the server can see it) and redirect the user to that URL.
For security (albeit through obscurity), make the filename something hideous (eg a hash of their username and a description of the file) and make sure people can't get a directory listing of the dir it lives in. Might make sense to date-tag the file (eg: filename-year-month-day.ext) so you can run something automatic to clean up the files after 24 hours.
Upvotes: 1