【问题标题】:wget not working when called from exec() or shell_exec()从 exec() 或 shell_exec() 调用时 wget 不工作
【发布时间】:2016-05-08 16:49:59
【问题描述】:

我正在尝试将我编写的 wget 命令集成到 php 脚本中。该命令递归地下载网站上的每个 html/php 文件(这是我在 file_get_contents() 中没有找到的必需功能)。我已经在终端窗口中测试了 wget 命令,但是当使用 exec() 或 shell_exec() 执行它时,没有任何反应。我没有收到任何错误或警告。

这是有问题的命令,

wget --recursive -m --domains oooff.com --page-requisites --html-extension --convert-links -R gif,jpg,pdf http://www.oooff.com/

我尝试过来自 exec() 和 shell_exec() 的简单 wget 命令(参数不多),但它们也不起作用。

如果 wget 不是一个选项,我愿意使用其他方法下载整个网站。

我现在拥有的代码是,

exec("wget google.com", $array);

那么当打印数组时它是空的

【问题讨论】:

  • 你的php代码是什么?
  • @CharlSteynberg 功能开启,问题依旧
  • @mh-cbon 我的代码是 exec("wget google.com", $array);然后我打印数组,它是空的,没有文件出现

标签: php exec wget shell-exec


【解决方案1】:

我必须指定 wget 的路径。新命令:

exec("/usr/local/bin/wget google.com", $array);

【讨论】:

  • 使用 $return_var 来检查。如果不是 0,那么就出了问题。
【解决方案2】:

使用适当的选项调用 wget

-q to remove it s information output
-O - to output the request response on stdout

php -r 'exec("wget -q -O - google.com", $array);var_dump($array);'

【讨论】:

    【解决方案3】:

    在我们的例子中,wget 没有足够的权限将 wget 文件保存在当前目录中。解决方案:

    $dir = __DIR__.'/777folder/';
    exec("/usr/bin/wget -P ".$dir." --other-options");
    

    在哪里

    -P,  --directory-prefix=PREFIX  save files to PREFIX/...
    

    ps。我们还添加了/usr/binwhereis wget,但在我们的系统中,没有它也可以正常工作

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-11-09
      • 1970-01-01
      • 2014-11-25
      • 2014-10-25
      • 1970-01-01
      • 1970-01-01
      • 2011-07-15
      • 2013-03-24
      相关资源
      最近更新 更多