Thanks all. I will work on all the options and let you know how it went :) On Thu, Feb 14, 2008 at 10:37 AM, Nathan Rixham <nrixham@xxxxxxxxx> wrote: > > Jochem Maas wrote: > > Ritesh Nadhani schreef: > >> On Feb 13, 2008 6:03 PM, Richard Lynch <ceo@xxxxxxxxx> wrote: > >>> On Wed, February 13, 2008 4:28 am, Ritesh Nadhani wrote: > >>>> I have a situation where I have to copy something like 1000 files one > >>>> by one to a temporary folder. Tar it using the system tar command and > >>>> let the user download the tar file. > >>>> > >>>> Now while the copy is going on at server, I want to show some progress > >>>> to the user at client side. Most of the tutorial I found on net was > >>>> about showing progress while a file is being uploaded from client to > >>>> server. In this case the client has the info but for my case, the > >>>> client has no info. > >>>> > >>>> A similar was problem was solved at > >>>> http://menno.b10m.net/blog/blosxom/perl/cgi-upload-hook.html but its > >>>> in PERL and uses some form of hook. I have no clue how to do it in > >>>> PHP. > >>>> > >>>> Any clues or right direction would be awesome. > >>> First of all, don't do that. :-) > >>> > >>> Instead, set up a "job" system of what should be copied/tarred, and > >>> then notify the user via email. > >>> > >>> Don't make the user sit there waiting for the computer! > >>> > >>> If you absolutely HAVE to do this due to a pointy-haired boss... > >>> > >>> <?php > >>> $path = "/full/path/to/1000s/of/files"; > >>> $dir = opendir($path) or die("Change that path"); > >>> $tmp = tmpname(); //or whatever... > >>> while (($file = readdir($dir)) !== false){ > >>> echo "$file<br />\n"; > >>> copy("$path/$file", "/tmp/$tmp/$path"); > >>> } > >>> exec("tar -cf /tmp/$tmp.tar /tmp/$tmp/", $output, $error); > >>> echo implode("<br />\n", $output); > >>> if ($error){ > >>> //handle error here! > >>> die("OS Error: $error"); > >>> } > >>> ?> > >>> > >>> shameless plug: > >>> //handle error here could perhaps use this: > >>> http://l-i-e.com/perror. > >>> > >>> -- > >>> Some people have a "gift" link here. > >>> Know what I want? > >>> I want you to buy a CD from some indie artist. > >>> http://cdbaby.com/from/lynch > >>> Yeah, I get a buck. So? > >>> > >>> > >> > >> I was actually doing what you just gave the code for. As of now, I was > >> doing something like: > >> > >> """" > >> for file in files: > >> copy from source to folder > >> echo "Copying files encapsulated in ob_flush()" > >> > >> tar the file which hardly takes time on the filessyetm but does take > >> some time > >> > >> Provide the link to the tar > >> """ > >> > >> So at the client side it was like: > >> > >> Copying file #1 > >> Copying file #2 > >> .... > >> Download link > >> > >> I though I could apply some funkiness to it by using some AJAX based > >> progress bar for which the example showed some sort of hooking and all > >> which I thought was too much for such a job. I will talk to my boss > >> regarding this and do the necessary. > >> > >> BTW, whats the issue with AJAX based approach? Any particular reason > >> other then it seems to be a hack rather then an elegant solution > >> (which is more then enough reason not to implement it...but I wonder > >> if there is a technical reason to it too)? > > > > the problem with the AJAX approach is the fact that there is absolutely > > no reason for a user to sit staring at the screen. hit 'Go' get an > > email when it's done, do something else in the mean time. > > > > of course a PHB might demand functionality that gives him/her an excuse to > > watch a progress bar ... in which case why not waste man hours making it a > > funky web2.0 deal ... heck go the whole hog and use 'comet technique' to > > push update info to the browser. > > > >> > > Can't see any problem with going down the ajax route myself (depending > on how many concurrent users you expect) - A simple ajax style poll > every second would suffice. > > You could always use the fancily named yet really old "comet technique" > aswell.. slap the script in a "magic" iframe and ob_flush whenever you > have new data to send. > > To be honeswt, both are trade-offs on a technology which isn't around > yet. With ajax you've got to spawn a new thread for every request (say 1 > per second, 100 concurrent users, that's 100 requests per second minimum > on your server) OR with comet you've got 100 long lasting worker threads > going. > > If you do go comet, it's worth investigating mod event for apache 2.* > http://httpd.apache.org/docs/2.2/mod/event.html > > Nath > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- Ritesh http://www.riteshn.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php