in reply to Re: GET a file without waiting for the result?
in thread GET a file without waiting for the result?

Hmm. The main problem is that the script is supposed to run via Apache, and is supposed to print "1", which will signal that it's finished. After this it will fetch the file and do some other stuff, but this won't be printed to the user.

Maybe it's possible to tell Apache that the script is finished immediately after the "1" is printed, so that the web page stops loading, but the script continues to work in the "background"?
There isn't a problem that the script takes time, the problem is that the system that calls the URL can't wait for the webpage to load.
  • Comment on Re^2: GET a file without waiting for the result?

Replies are listed 'Best First'.
Re^3: GET a file without waiting for the result?
by Corion (Patriarch) on Sep 22, 2010 at 13:46 UTC
      Kind of.
      Maybe there's a simpler way?:-D

        If your program runs within any webserver environment, you won't get things any simpler than that unless you can explain what environment exactly you have.

        Spawning an external process and displaying its progress is about as simple as you can get.

Re^3: GET a file without waiting for the result?
by ikegami (Patriarch) on Sep 22, 2010 at 16:39 UTC

    It's curious that you don't want any error checking (in which case you could use Watch Long Processes Through CGI).

    I can see two approaches.

    • Spawn a task to do the work.

      use POSIX qw( setsid ); print "Content-Type: text/plain\n"; print "\n"; print "1"; my $pid = fork(); exit(0) if !defined($pid) || $pid; open STDIN, '</dev/null' or die; open STDOUT, '>/dev/null' or die; open STDERR, '>&STDOUT' or die; setsid(); ... handle request ...
    • Assign the work to an existing task or to a cron job.

      ... queue request in a file or database ... print "Content-Type: text/plain\n"; print "\n"; print "1";