exec() in the background

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
Galahad
Forum Contributor
Posts: 111
Joined: Fri Jun 14, 2002 5:50 pm

exec() in the background

Post 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?
qartis
Forum Contributor
Posts: 271
Joined: Sat Dec 14, 2002 4:43 pm
Location: BC, Canada
Contact:

Post 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`;
Galahad
Forum Contributor
Posts: 111
Joined: Fri Jun 14, 2002 5:50 pm

Post 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).
User avatar
Unifex
Forum Newbie
Posts: 14
Joined: Mon Jul 07, 2003 12:29 am

Post 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.
Post Reply