You are here: Re: exec, run until finished « PHP Programming Language « IT news, forums, messages
Re: exec, run until finished

Posted by Mladen Gogala on 01/03/07 08:12

On Mon, 01 Jan 2007 21:22:30 +0000, Andy Hassall wrote:

> 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.
>

In my opinion, long running things are not suitable for web interface. If
you have a batch job, you can put it on some kind of a queue and
communicate results. Having browser waiting for the data from the server
for extended periods of time is an extremely bad practice, application
design-wise. It is practically guaranteed to infuriate users and make them
demand the designer's head on an aluminum platter. No need to waste silver.



--
http://www.mladen-gogala.com

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация