|
Posted by Andreas.Burman on 01/02/07 14:00
Andy Hassall skrev:
> On 1 Jan 2007 11:48:57 -0800, Andreas.Burman@gmail.com wrote:
>
> >I call a program through exec that can take a long time to execute.
> >This is fine but I would like to show some kind of animation or
> >something while the program is running and when it is finished letting
> >the user download the file.
> >
> >Right now I'm using code similar to this simplified example:
> >
> >----- index.php -----
> ><form method="post" action="genetate.php" target="_blank">
> > <input type="submit" value="Generate!"/>
> ></form>
> >
> >----- generate.php -----
> ><?php
> > $tmpname = time() . md5("bla");
> >
> > // Writes to $tmpname
> > exec("takesalotoftime $tmpname");
> >
> > $len = filesize("$tmpname");
> >
> > header('Content-type: application/postscript\r\n');
> > header("Content-Length: $len;\r\n");
> > header('Content-Disposition: attachment; filename="' . $tmpname
> >. '"\r\n');
> >
> > readfile("$tmpname");
> >?>
> >
> >So what is the best way to start the exec, show an animation until it
> >is finished and then send the file to the user?
>
> One approach; show a page with an animated gif, flush the page, run the
> long-running exec, then do a Javascript redirection when it's done (bearing in
> mind that it's not 100% reliable).
>
> Or move it back a step; redirect to page a with an animation and a notice to
> the user to be patient, redirect to the long-running page and rely on the
> browser not updating the page until the next one starts returning stuff.
>
> If the process can provide feedback on the progress, then proc_open and
> HTML_Progress from PEAR may let you get more sophisticated.
>
> You have a few options since it looks like you're writing to a file so you can
> always fetch that on a separate page - although that runs the risk of leaking
> temporary files if it's not a true temp file (but if it is a true temp file
> then it'd disappear anyway).
>
> How long does it take? You may run into maximum execution time limits as well
> as the users' impatience.
Thanks for all the suggestions but it looks like i'am not going to need
them. The execution took between 30-60 seconds on my test server, but
when I tried it on the real server it took between 1-5 seconds :)
> --
> Andy Hassall :: andy@andyh.co.uk :: http://www.andyh.co.uk
> http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
[Back to original message]
|