Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php shell exec wget不在后台运行_Php_Shell_Exec_Wget - Fatal编程技术网

php shell exec wget不在后台运行

php shell exec wget不在后台运行,php,shell,exec,wget,Php,Shell,Exec,Wget,我想运行wget,如下所示 shell_exec('wget "'http://somedomain.com/somefile.mp4'"'); sleep(20); continue my code... 我想要的是让PHP等待shell_exec wget文件下载完成,然后继续编写其余代码。我不想等待设定的秒数 我该怎么做,因为当我运行shell_exec wget时,文件将开始下载并在后台运行,PHP将继续 shell_exec会等待命令完成-因此您根本不需要sleep命令: <?

我想运行wget,如下所示

shell_exec('wget "'http://somedomain.com/somefile.mp4'"');
sleep(20);
continue my code...
我想要的是让PHP等待shell_exec wget文件下载完成,然后继续编写其余代码。我不想等待设定的秒数


我该怎么做,因为当我运行shell_exec wget时,文件将开始下载并在后台运行,PHP将继续

shell_exec会等待命令完成-因此您根本不需要sleep命令:

<?php
shell_exec("sleep 10");
?>

# time php c.php
   10.14s real     0.05s user     0.07s system
应该是

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

您的URL是否包含字符(&C)?如果是这样,wget可能会进入后台,shell_exec()可能会立即返回

例如,如果$url为“http://www.example.com/?foo=1&bar=2“,在命令行上传递时,您需要确保它是单引号:

shell_exec("wget '$url'");
否则shell会误解&

通常,转义命令行参数是一个好主意。最全面的方法是使用escapeshellarg():


它不等待我的案例,它只运行下一行代码。
shell_exec("wget '$url'");
shell_exec("wget ".escapeshellarg($url));