Page 1 of 1

fork from php or perl

Posted: Mon Dec 05, 2005 6:30 am
by gero
Hello everyone.

I've a perl application which has run time of several hours.
Till now I launch it from a ms-dos windows with output on file.
Now I'm trying to insert in in a web contest, using a submit in a php form that call a system with the launch of the perl script.

from php code:

$command="perl $dir\proof.pl";
system($command);

The system is syncronous, and then it blocks the browser window till the end of execution. Impossible.
I've tried with the forks both in php and in perl, but it seems that anyway the father process waits for the completion of the child.
Maybe I did something wrong.
Has anyone suggestions?

Thank you very much.

gero

Posted: Mon Dec 05, 2005 6:40 am
by onion2k
I think you need to use exec() and redirect the output from the perl somewhere other than returning it to the PHP script. Something like..

Code: Select all

exec("perl $dir\proof.pl > dev/null");
I've not got a *nix box I can try that on around at the moment though..

Posted: Mon Dec 05, 2005 9:22 am
by timvw
Actually, you might want to call a script and execute it on the background:

Code: Select all

`/usr/bin/something &`;

Or, with perl close stdio and fork away.. I should lookup if the parent process keeps waiting for the child process or not by default, but i'm pretty sure the manual will tell you that ;)

Code: Select all

close(1);
close(2);
my $pid = fork;
if (undef $pid) print "fork failed";
if ($pid > 0) print "parent process";
if ($pid == 0) print "child process";