Apache CGI and spawning another process

Discussion in 'Ruby' started by Francis Hwang, May 7, 2005.

  1. Hey all,

    There's probably a very easy answer to my question, but I've never been
    very good with managing process and haven't been able to find this
    addressed directly in the archives. So: I'm trying to have a CGI script
    that will publish a ton of different XML files. The publishing process
    is pretty long, maybe it will run 10 or 15 minutes, but it's not
    complicated, and the user doesn't need any feedback, they just need a
    message that says "we started the process; it should be done in a few
    minutes."

    I tried running code that looks like this:

    is_parent = fork
    system '/some/external/script.rb' unless is_parent
    print "Location: /admin_page\n"

    And this works on the command-line. It prints the location line right
    away and then ends quickly, leaving the external script to run in the
    background until it finishes of its own accord.

    But the same script doesn't work in Apache ... it runs the external
    script, but hangs and doesn't exit. I guess Apache is treating the
    spawning of external processes differently. Anybody have experience
    with this? Is there some really obvious solution I'm missing?

    tia,
    Francis Hwang
    http://fhwang.net/
    Francis Hwang, May 7, 2005
    #1
    1. Advertising

  2. Francis Hwang

    James Britt Guest

    Francis Hwang wrote:
    > Hey all,
    >

    ..

    >
    > But the same script doesn't work in Apache ... it runs the external
    > script, but hangs and doesn't exit. I guess Apache is treating the
    > spawning of external processes differently. Anybody have experience with
    > this? Is there some really obvious solution I'm missing?


    Hack, off the top of my head, untested (but I may yet go try it)
    Write a task to crontab and set the time a few seconds from now.

    Or: Just have a cron job that pulls tasks off a file-based queue.

    Plus the usual caveats about duplication, notification, hung tasks, and
    so on.

    James
    James Britt, May 8, 2005
    #2
    1. Advertising

  3. On Sun, May 08, 2005 at 07:44:51AM +0900, Francis Hwang wrote:
    > Hey all,
    >
    > There's probably a very easy answer to my question, but I've never been
    > very good with managing process and haven't been able to find this
    > addressed directly in the archives. So: I'm trying to have a CGI script
    > that will publish a ton of different XML files. The publishing process
    > is pretty long, maybe it will run 10 or 15 minutes, but it's not
    > complicated, and the user doesn't need any feedback, they just need a
    > message that says "we started the process; it should be done in a few
    > minutes."
    >
    > I tried running code that looks like this:
    >
    > is_parent = fork
    > system '/some/external/script.rb' unless is_parent
    > print "Location: /admin_page\n"
    >
    > And this works on the command-line. It prints the location line right
    > away and then ends quickly, leaving the external script to run in the
    > background until it finishes of its own accord.
    >
    > But the same script doesn't work in Apache ... it runs the external
    > script, but hangs and doesn't exit. I guess Apache is treating the
    > spawning of external processes differently. Anybody have experience
    > with this? Is there some really obvious solution I'm missing?
    >


    You should probably close the $stdout (and possibly $stdin and $stderr)
    streams in the child process, otherwise apache will think there is still
    more output coming.

    cheers,
    Joost Diepenmaat.
    Joost Diepenmaat, May 9, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    4
    Views:
    1,269
    Kevin Spencer
    Feb 8, 2005
  2. Marianne
    Replies:
    4
    Views:
    557
    Juan T. Llibre
    Jul 7, 2005
  3. LarsenMTL
    Replies:
    4
    Views:
    671
    Eric Walstad
    Nov 4, 2004
  4. brolewis

    Spawning, and Killing, a Process

    brolewis, Jan 31, 2005, in forum: Python
    Replies:
    0
    Views:
    325
    brolewis
    Jan 31, 2005
  5. Prachi
    Replies:
    7
    Views:
    207
Loading...

Share This Page