2009/11/12 Nick Brown <nick / nick-brown.com>:
> I want a CGI script to fire off another process and continue executing
> (or even terminate) without waiting for the process to finish. I wrote
> this:
>
> #!/usr/bin/ruby
> require 'cgi'
> c = CGI.new
> fork do sleep 5 end
> c.out {"hello!\n"}
>
> When I execute that from the command line, it IMMEDIATELY prints
> "Content-Type...hello!" and exits. When I run it on Apache and access it
> from my browser, on the other hand, it PAUSES for five seconds, THEN
> displays "hello!".
>
> What's going on? Why does it behave differently with Apache?

All sorts of possible reasons: Apache might buffer your output and
maybe it even waits for the child to return.

What happens if you do this:

#!/usr/bin/ruby
require 'cgi'
c = CGI.new

fork do
  $stdin.close
  $stdout.close
  $stderr.close
  sleep 5
end

c.out {"hello!\n"}

Cheers

robert


-- 
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/