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

Hi there

Until now, I have used perl mainly to work with local files and databases.
For my current project, I want to have my script running on a webserver since it will be running an "endless loop". In other words, the script checks for something every 10 seconds and therefore, executing it on a server makes sense.
My question: How do I execute a perl script on a server and keep it running? Simply via SSH using the "&" to fork the process?

Thanks for your help.
EDIT:
Looks like this has to be done as CGI or CRON. Right?

Replies are listed 'Best First'.
Re: Execute a script on a server
by daxim (Curate) on Sep 09, 2013 at 10:09 UTC
Re: Execute a script on a server
by karlgoethebier (Abbot) on Sep 09, 2013 at 17:43 UTC

    Wasn't this the classic?

    #!/usr/bin/env perl use POSIX qw(setsid); print daemonize(); sub daemonize { my $child = fork; if ( definded ($child) ) { exit 0 ; } else { die qq(I really can't...!\n); } setsid(); open( STDIN, "</dev/null" ); open( STOUT, ">/dev/null" ); open( STDIN, ">&STDOUT" ); chdir '/'; umask(0); ENV{PATH}=q(/what/you/like); return $$; }

    Please see also Parallel::ForkManager.

    Regards, Karl

    «The Crux of the Biscuit is the Apostrophe»