tags:

views:

920

answers:

1

Related: see here

I've got this command:

exec("(wget  -O http://domain/file.zip && mysql -u user -ppassword database -e \"UPDATE \\`table\\` SET \\`status\\` = 'live' WHERE \\`id\\` = '1234'\") & echo \$!");

The above command works fine, however PHP waits for the video to finish downloading before going on to the next download. The following line, however, sends the download to the background, which is what I'm trying to achieve from the previous line.

exec("wget -O http://domain/file.zip &>/dev/null & echo \$!");

How do I go about changing the first line above to send the download to the background?

+2  A: 

You have to make you use & to send the the process to the background and that you redirect all output. So you need to add

> /dev/null 2>&1 &

at the end of your command. So you should end up with something like this:

exec("(wget  -O http://domain/file.zip && mysql -u user -ppassword database -e \"UPDATE \\`table\\` SET \\`status\\` = 'live' WHERE \\`id\\` = '1234'\") echo \$! > /dev/null 2>&1 &");

[Edit]

To make thing simpler, you can also move the wget and the update to another php file that you would call with exec. So you would end up with only

exec("php NewFile.php > /dev/null 2>&1 &");
Eric Hogue
Running the above line does not start the wget download at all, however doesn't hang PHP (which is what I wanted). Any reason why it might not start the wget command?
Don Wilson
You should try to pass exec an array to get what the command returned. You can see the syntax of exec here: http://ca2.php.net/function.exec
Eric Hogue