php shell exec wget不在后台运行 [英] php shell exec wget to run not in background

查看:110
本文介绍了php shell exec wget不在后台运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想按以下方式运行wget

I want to run wget as follows

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

我要让PHP等待shell_exec wget文件下载完成,然后再继续其余代码.我不想等待设定的秒数.

What I want is to let PHP wait for the shell_exec wget file download to finish before continuing on with the rest of the code. I don't want to wait a set number of seconds.

该如何执行,因为在运行shell_exec wget时,该文件将开始下载并在后台运行,并且PHP将继续.

How do I do this, because as I run shell_exec wget, the file will start downloading and run in background and PHP will continue.

推荐答案

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

Does your URL contain the & character? If so, your wget might be going into the background and shell_exec() might be returning right away.

例如,如果$ url为"http://www.example.com/?foo=1&bar=2",则需要确保在命令行中传递时将其用单引号引起来:

For example, if $url is "http://www.example.com/?foo=1&bar=2", you would need to make sure that it is single-quoted when passed on a command line:

shell_exec("wget '$url'");

否则,外壳会误解&.

Otherwise the shell would misinterpret the &.

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

Escaping command line parameters is a good idea in general. The most comprehensive way to do this is with escapeshellarg():

shell_exec("wget ".escapeshellarg($url));

这篇关于php shell exec wget不在后台运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆