Returning a response with Ruby CGI before script is finished? -
anyone know how send cgi response in ruby before cgi script finished executing?
i'm creating fire-and-forget http api. want client push data me via http , have response return successfully, , then swizzles data , processing (without client having wait response).
i've tried several things don't work, including fork. following wait 5 seconds when invoked via http.
#!/usr/bin/ruby require 'cgi' cgi = cgi.new cgi.out "text/plain" "1" end pid = fork if pid # parent process.detach pid else # child sleep 5 end
i answered own question. turns out need close $stdin, $stdout, , $stderr in child process:
#!/usr/bin/ruby require 'cgi' cgi = cgi.new cgi.out "text/plain" "1" end pid = fork if pid # parent process.detach pid else # child $stdin.close $stdout.close $stderr.close sleep 5 end
Comments
Post a Comment