Question

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?

Was it helpful?

Solution

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 &"); 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top