Php shell exec wget not running in the background

I want to run wget as follows

shell_exec('wget "'http://somedomain.com/somefile.mp4'"'); sleep(20); continue my code... 

I want PHP to wait for the shell_exec file to complete loading before continuing with the rest of the code. I do not want to wait for the specified number of seconds.

How to do this, because when shell_exec starts, the wget file will start downloading and running in the background, and PHP will continue to work.

+4
source share
2 answers

Is there a character and character in your url? If so, your wget can go in the background, and shell_exec () can return immediately.

For example, if $ url is "http://www.example.com/?foo=1&bar=2", you need to make sure that it is sent in one quote when passing on the command line:

 shell_exec("wget '$url'"); 

Otherwise, the shell misinterprets &.

Escaping command line options is a good idea overall. The most complete way to do this is escapeshellarg ():

 shell_exec("wget ".escapeshellarg($url)); 
+3
source

shell_exec waits for the command to complete - so you don’t need the sleep command at all:

 <?php shell_exec("sleep 10"); ?> # time php c.php 10.14s real 0.05s user 0.07s system 

I think your problem is most likely the quotation marks on this line:

 shell_exec('wget "'http://somedomain.com/somefile.mp4'"'); 

he should be

 shell_exec("wget 'http://somedomain.com/somefile.mp4'"); 
0
source

All Articles