tags:

views:

150

answers:

4

I am trying to write a Perl script that takes data from a user, creates a HTML file on the basis of that data, redirects to this HTML file and then performs some computations. The problem I am facing is that the browser does not redirect to the new HTML page unless the computations are completed. Please suggest a solution.

+2  A: 

It sounds like you need to run your computations in the background. One way to do this is to use a fork() call. I think you may find this question helpful.

Trey
Yes, you'll need to spawn a background process to do what you want.
pioto
I tried that too. I put the code for refreshing the page into child and for computation into parent. What happens is that the html file is created but then the browser does not redirect to the new page but instead continues with the computation.
amit
I think the code for refreshing the page should have gone in the parent. However, Proc::Background is probably the simplest way to do what you need if you can put your computations in a separate file to be executed.
Trey
+1  A: 
print "Location: http://yoursite.com/path/to/your/page.html\n";

(note this is how you do it in Perl but "Location" is an HTTP directive. Outputting that string works in any language)

Cfreak
I was using following statement.print '<meta http-equiv="refresh" content="0;URL=',$url_result,'">';Shall I use Location one for this?
amit
Yes you should replace the META tag with what I have. Make sure you aren't printing out a different header. For HTML you have to have print "Content-Type: text/html\n"; My example would replace that header. In other words if you use my method that's the only thing you can print out. Printing out something else will not be seen at best and likely prevent the redirect from happening.
Cfreak
+2  A: 

See Randal Schwartz's article Watching long processes through CGI.

molecules
A: 

Hey Guys.

Thanks for your help. In the meantime I took a different approach. I dont know if it is good or not but it works. I started writing a logfile putting in parameters necessary for the computations and started a cronjob. So as soon as any new entry in that logfile, computations start in the background.

Thank you once again.

amit
Edit your question, or add a comment. Don't add an answer, that isn't really an answer.
Brad Gilbert