Re: Copying 1000s files and showing the progress
| From: | Jochem Maas | Date: | Thu, 14 Feb 2008 13:19:34 +0000 |
| Subject: | Re: Copying 1000s files and showing the progress | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-269292@lists.php.net to get a copy of this message | ||
Ritesh Nadhani schreef:
On Feb 13, 2008 6:03 PM, Richard Lynch <ceo@l-i-e.com> wrote: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.On Wed, February 13, 2008 4:28 am, Ritesh Nadhani wrote: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)?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?