1

In the interest of cleaning up temporary files on the webserver, I'm wondering if there's any way to tell when X-Sendfile downloads complete... maybe in a log somewhere? My understanding currently is that once you pass off the headers it is basically on its own.

janw
  • 8,758
  • 11
  • 40
  • 62
Osan
  • 187
  • 1
  • 3
  • 13

3 Answers3

1

If possible, you can temporary shutdown apache gracefully with apachectl -k graceful-stop. When stopped, after all requests are finished, you can remove the temporary files and start apache again.

Ward Bekker
  • 6,316
  • 9
  • 38
  • 61
0

Apache only logs a hit once the connection's closed, which presumably would be whenever the download is finished. So monitoring the access log for the specific download url would tell you when it's completed - comparing the logged bytes-sent v.s. how much you expected to send will also tell you if the download was successful or if it was aborted.

Marc B
  • 356,200
  • 43
  • 426
  • 500
  • Ack, can confirm even with x-sendfile it only registers after completion. You can add a custom log-format if you need to know more about the specific request. – Wrikken Aug 03 '11 at 19:13
0

I don't know of such way, but if you are running on Linux, then I think you can safely remove the file even if a download is still in progress. The file will be deleted immediately but the inode will be kept intact until all references to it are gone.

sagi
  • 5,619
  • 1
  • 30
  • 31
  • I tried using unlink($fileLocation) and passthru("rm -f $fileLocation")... both immediately removed the file and killed off the download =(. CentOS 5 btw. – Osan Aug 03 '11 at 19:20
  • Are you doing it from the same PHP script that sent the header? If you do, then it is likely that you deleted the file before the header was ever sent. You need to give it some time - for example, run a cron job every hour that deletes files who's modification time is over 1 hour (or their access time, if your filesystem tracks that). – sagi Aug 03 '11 at 19:22
  • 1
    ..or you can delete it in the users's next request. – Karoly Horvath Aug 03 '11 at 19:40