php shell exec wget不在后台运行
我想运行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命令: <?
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));