LiTinOveWeedle has asked for the wisdom of the Perl Monks concerning the following question:

Hi my brothers,
I made script which is able to transfer file over net by ftp. This script is called from web interface as hyperlink -cgi-bin/ftp.pl When I click on hyperlink at my pages, script start, print simple html page - "script is started" - which is return as destination of hyperlink, and then start ftp transfer....

If ftp transfer is done before web server timeout all running well. But, if not script is terminated by webserver and so ftp transfer is interupted. Is there any way, how to start script from web, but start it as independent thread - to be independent on webserver?

If you know how to do this .... THX for your help

Li Tin O've Weedle
mad Tsort's philosopher

Replies are listed 'Best First'.
Re: webserver independent script
by mpolo (Chaplain) on May 10, 2001 at 12:39 UTC
    I think that part of your solution will be to use no-parse headers (nph). Normally, a CGI script doesn't send anything to the web server until the page is complete, which can give you a timeout problem. No-parse headers allow you to send data directly to the browser and prevent the timeout (You set up a Script is started... page and add more dots -- or whatever -- every few seconds.)

    A recent article on splash pages with search engines may be applicable as well: How do I create a splash page in Perl.

    Update: Changed process->parse to correct error.

Re: webserver independent script
by Anonymous Monk on May 10, 2001 at 14:08 UTC
    I may be wrong about this, but perhaps if you are on Unix you could fork() a new process to do the ftp stuff?

    if ( fork() ) {exit} else { # ftp stuff }

    However, perhaps webservers kill all children at timeout too. Not sure.

    David

      Thx,
      last sentece is good question. I look at Web techniques Column 20 - Merlyn using fork for two proceses to: 1) redirect to some URL and 2) run long time process (in this case it's search routine) so I think it should work. - so that webserver don't kill child process, hope.

      Any suggestion?

      Li Tin O've Weedle
      mad Tsort's philosopher

        I had this problem in Web-FTP you need to fork and close STDOUT;

        at least, you need to close STDOUT if you want apache to tell the page the browser is done. I do a...

        fork() && exit(0); close STDOUT;
        which allows the browser to go on its merry way.
                        - Ant
      At least I realized that under win32 you must use system() or exec() commands after forking, to create independent process. So, at first fork, then daemonize child process (close STDIN and STDOUT) and then use system() or exec() to call part of code. This work well in my case and I hope it will work well in yours.

      Thanks to other monks who helped me to find out this problem.

      Li Tin O've Weedle
      mad Tsort's philosopher