On Sunday 27 October 2002 03:06, Matthew Smith wrote: > Anyone ever done a background process in XSP? I want to display a > progress update or something while my user is waiting for their form > data to be processed. - e.g. I have a button that generates a gzipped > HTML rendering of my website for uploading to a non AxKit server. How > would I know that my background process has finished and what the > results were?
> One approach is to fork-exec and put the PID of the forked process into > the session object. The XSP page could then have a refresh meta tag set > to a few seconds and check the PID each time it loads until the process > is finished. It could also check a log file or tmp filename based on > the PID of the forked process. I'd use this variant. It is technically the simplest one. Fast to implement, reasonable in performance/features. Note that you can replace a signalling file with an appropriate database table entry. (Not that I would use that, but for those rdbsomaniacs out there it's possible.) > In another approach, the forked process could somehow get hold of the > session object and put the results there as well as indicating that it > has not finished yet - maybe use a watchdog counter to detect if it > crashed. This one may work, too, but you get the added overhead of session file/database/whatever locking. Or, if you don't get locking right, it might even trash your session records every once in a while. Given the only advantage is some less files on your hard disk, I think it's not worth. > Perhaps there are more elegant ways? Well, the truely elegant way would be the following: Write a pure mod_perl handler. We need full control. Create a pipe, fork and do your task. You may work directly from there on if you like, exec() is not required. In the child, regularly write some progress information to the pipe. At the end, write result information. What you write is your thing, just make sure you can read and parse it in the parent process. In the parent process, directly send some HTML to start a page. Depending on your site design, this can be the regular site design, but make sure the browser is now at the "content" area (where the progress should show), and _not_ within a table (otherwise some browsers will not render it immediately). Enter a loop that read from the pipe and prints some text to the browser each time a new message comes in. When the child is done, print some HTML to finish the page. One important thing to watch is that you absolutely must send "something" to the browser once a minute, otherwise apache itself or intervening proxies or even the browser may consider the connection dead and close it. Also, make sure to set the usual "don't cache me" headers in the response. By the way, this works per CGI as well, at least with Apache 1. I've heard Apache 2 does some buffering, so that would fail. This is far more complex to implment with little gain - it might even hog your server's memory resources much more than the simple solution above. So you might still consider the simple variant. -- CU Joerg PGP Public Key at http://ich.bin.kein.hoschi.de/~trouble/public_key.asc PGP Key fingerprint = D34F 57C4 99D8 8F16 E16E 7779 CDDC 41A4 4C48 6F94 --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
