Re: Execute with No wait
by mrmick (Curate) on Aug 24, 2000 at 22:44 UTC
|
One solution, if you do not want to wait for the response, is to send a confirmation page that the script received the request. Once the script has received the request and sent the confirmation page, send all output to a file and not to STDOUT.
You can still test the resulting files vs. messages (but not to the client). If the test passes, the script can then send an email to the user's email address (this would have to be in the form?).
Another solution could be to send characters(maybe ' 's or '.'s), at intervals to the client. This could help overcome the timeout issues as well. If this aproach were taken, immediately send about 256 whitespace characters to overcome any buffers that may be in the server (or client). I have used this approach, along with '$|=1' to overcome timeout issues.
While there may be other/better solutions, I hope this helps.
Mick | [reply] |
|
|
| [reply] |
|
|
Actually, that behavior depends on the Webserver and OS.
As I recall you can close STDOUT and STDERR under Apache
on a Unix'ish box and Apache will dump the other end.
Tho a quick test reveals that it also kills the cgi too so
it is of little use to the original poster =)
Does anyone remember if there is a way to make Apache
leave the child alive after closing the connection? I have
spent too much time in mod_perl so I may have that on the
brain.
--
$you = new YOU;
honk() if $you->love(perl)
| [reply] |
|
|
|
|
|
|
merlyn,
I'm starting to get the picture. Please see my post below.
| [reply] |
|
|
So far this (these) seem to be the best possible solutions. Others seem to agree.
I'd most be interested in the first choice.
The 'work' script has a content-type of text/plain. I'm not sure how to go about adjusting STDOUT but this seems to be on the right track.
| [reply] |
RE: Execute with No wait
by merlyn (Sage) on Aug 24, 2000 at 22:56 UTC
|
| [reply] |
RE: Execute with No wait
by jlistf (Monk) on Aug 24, 2000 at 22:48 UTC
|
one possibility is to write a program that will output a simple page to the browser and then call another program that actually does the nitty gritty stuff. the browser will get a page and be satisfied and the other program will take care of dealing with the input.
jeff | [reply] |
|
|
Thanks for the reply.
This doesn't seem to work either. The 'simple page' will not display until the 'nitty gritty' finishes even though I am using $| = 1 :-(
| [reply] |
|
|
try using pipe/fork/exec/some-combination. you want to get the program that outputs the page to finish even when the other script is going on. I think you can do it with a combination of fork and pipe || exec. if you follow merlyn's link, it'll probably tell you exactly what to do.
jeff
| [reply] |
RE: Execute with No wait
by bastard (Hermit) on Aug 24, 2000 at 23:10 UTC
|
This isn't exactly what you are looking for, but you could use a non-parsd header script (NPH).
There are two parts needed:
- put the "nph-" prefix on the script name
- make sure to pass back from the script ALL headers required
(I believe it is still requred to return some sort of data periodically.)
A quick intro (with exmples) is here: http://www.wdvl.com/Authoring/Scripting/Tutorial/nph.html
For the other method. Do what mrmick suggested.
Have the script display an interim page (with a link to another script that will give you the results/status), but once you display the page you can then have the original script go off and do it's thing (recording results to a file).
The second script i mentioned would read the results of the file and display them to the user. (if the script isn't done yet, there would be no results. alternatively you may want to provide periodic status updates during the execution of the original script)
| [reply] |
|
|
| [reply] |
|
|
merlyn,
I didn't want you to think I wasn't taking your advice. In fact I've been following it. It took me a short while but I was actually reviewing 'search in progress' when I came back to check for replies.
So far this seems to be exactly what I was looking for! I *really* appreciate it and will let you know when I've done my re-write and tested.
Thanks again, bp
| [reply] |
|
|
Re: Execute with No wait
by gaspodethewonderdog (Monk) on Aug 24, 2000 at 22:51 UTC
|
sounds like you may want to unbuffer your output... try disabling buffering with
$| = 1;
I think that *may* help
| [reply] |
|
|
Thanks for the reply.
Unfortunately doesn't work :-(
| [reply] |
Re: Execute with No wait
by chromatic (Archbishop) on Aug 26, 2000 at 00:20 UTC
|
So far, your options are limited to spawning another process (via fork or some Win32::Process-enabled system call) or using some sort of keepalive technique to keep sending data to the client.
The former is better than the latter, but here's another idea. Have your CGI program only collect the data, and write it to a special directory somewhere (or a file, socket, pipe, or whatever). Have a second process (not connected to the web server in any way) do the actual processing. Your CGI can exit and close the browser connection right after it finishes collecting and storing the information, while the other process can do what it needs to do after the user has gone on to something else. | [reply] |
RE: Execute with No wait
by Adam (Vicar) on Aug 31, 2000 at 04:41 UTC
|
Open the command to a pipe. This should return immediatly and will allow you to retrieve the output at your convenience.
open PIPE, "$command |" or die "Failed to execute '$command'\n$!";
Then later, if you want, you can read from PIPE. | [reply] [d/l] |