Page 1 of 1
exec() in the background
Posted: Wed Jul 09, 2003 5:03 pm
by Galahad
I'm trying to get a php script to automatically generate an iso. I'm using this command:
Code: Select all
<?php
exec("mkisofs -fRrlJ -V'Backup CD $max' -P'Me' -quiet -o $archiveDir"."cd$max.iso $path* &");
?>
It makes the iso just like I want it to. However, it doesn't do it in the background. The php script just hangs until the command is finished. I've also tried:
Code: Select all
<?php
exec("mkisofs -fRrlJ -V'Backup CD $max' -P'Me' -quiet -o $archiveDir"."cd$max.iso $path* > /dev/null");
?>
That doesn't work either. Any ideas?
Posted: Wed Jul 09, 2003 5:10 pm
by qartis
Maybe try
Code: Select all
$cmd = "mkisofs -fRrlJ -V'Backup CD $max' -P'Me' -quiet -o $archiveDir"."cd$max.iso $path*";
$result = `$cmd`;
Posted: Wed Jul 09, 2003 5:22 pm
by Galahad
quartis, thanks for the reply. However, there's nothing in that command to tell it to operate in the background. The '&' in my first command tells the shell to execute the command in the background. The '> /dev/null' in my second command redirects output from the command to /dev/null (basically it just gets rid of it). The '&' and the output redirection are the two ways I know to execute something in the background, from a real shell that is.
I also had tried using sys_exec() instead of just exec(). The manual claims it's identical to the `...`. It didn't work either. Anyway just to be sure I tried your `$cmd` suggestion, and it still executed in the foreground (but still created the iso fine).
Posted: Wed Jul 09, 2003 6:02 pm
by Unifex
You want to use
system() function where you previously used exec.
Code: Select all
<?php
system("mkisofs -fRrlJ -V'Backup CD $max' -P'Me' -quiet -o $archiveDir"."cd$max.iso $path* &");
?>
Read through the comments on that page. There's a few people talking about running things in the background.