0

I have a directory listing script that I made, and I would like to know what direction I need to go in to make an option for a specific directory to be downloaded as a tarball. A cronjob would not be acceptable because I would like this to be on demand so CPU cycles aren't wasted on unwanted content, but I would also like caching for content that has been requested. An ideal solution, which would exclude caching, would be to output the tar command to stdout, but how would I send that through PHP without having to wait for the command to finish? Some direction on this would be helpful.

Clay Freeman
  • 533
  • 5
  • 17
  • 1
    how often does the directory contents change? if infrequently i would crate the tarball with a cronjob say daily. you could also keep track of when the directory changes then just tarball it if it changes. –  Dec 26 '12 at 03:44
  • This is not ideal for the hosting situation I am in. – Clay Freeman Dec 26 '12 at 03:50
  • 2
    Disregarding the caching, the simplest approach would be `passthru("tar -cz dir/");` – mario Dec 26 '12 at 03:53
  • the information provided is not ideal for answering ;) –  Dec 26 '12 at 03:54
  • @mario submit that as an answer. This will work perfectly. – Clay Freeman Dec 26 '12 at 04:04

1 Answers1

0

To send it without waiting you could execute the gz command while using "ob_implicit_flush()", not sure if the command will read while still running but you can run it in the background and read from it while outputing into a file or something. You could also check the date on the dir/files and then run the gzip script

MitziMeow
  • 635
  • 4
  • 13
  • I don't believe this will work, as the return from shell_exec will block it from flushing. – Clay Freeman Dec 26 '12 at 04:05
  • Not if you run it non-blocking and constantly read the file, see here http://stackoverflow.com/questions/222414/asynchronous-shell-exec-in-php – MitziMeow Dec 26 '12 at 04:07