fork from php or perl

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
gero
Forum Newbie
Posts: 1
Joined: Mon Dec 05, 2005 6:19 am

fork from php or perl

Post 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
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post 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..
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post 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";
Post Reply