【问题标题】:wget inside exec does not generate any output or saves the webpagewget inside exec 不生成任何输出或保存网页
【发布时间】:2012-03-23 01:22:18
【问题描述】:

我正在开发一个小型个人项目,该项目可以使用 PHP 和 wget 将整个网页保存到我的本地磁盘上。

基本上当我传递一个 URL 时,它应该保存网页,通过以下方式修复 URL 和图像:

exec('cd application/collection; wget -k -p --user-agent=Firefox/11.0 google.com, $output', $return);

print_r($output); // Array( )
print_r($return); // 0

奇怪的是,我没有得到任何输出,目录中没有保存任何内容(这是正确的目录,我可以确认)。我的本地主机正在运行用户_www,我怎样才能允许通过 PHP 的 exec 函数使用 wget 保存网页?

我不能使用file_get_contents,因为它不能修复 URL 和图像。

【问题讨论】:

  • 您是在两个不同的服务器上尝试这个吗?如果是的话,wget 是否都在你的 PATH 中?

标签: php exec wget


【解决方案1】:

试试这个:

exec('cd application/collection; /usr/bin/wget -k -p --user-agent="Firefox/11.0" "http://www.google.com"', $output, $return );

【讨论】:

  • 我没有得到任何输出,但现在返回的是127
  • 它在我的环境中正常工作。尝试使用绝对路径。
  • 我做了,两个都没效果。
【解决方案2】:

你可能已经解决了这个问题,但谷歌将我重定向到这个 Q,所以,对于其他任何人:

您需要将标准错误重定向到标准输出:2>&1

exec('cd application/collection; wget -k -p --user-agent=Firefox/11.0
google.com 2>&1', $output, $return);
print_r($output); 
print_r($return); 

【讨论】:

    猜你喜欢
    • 2018-01-05
    • 1970-01-01
    • 1970-01-01
    • 2017-02-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-04
    • 1970-01-01
    相关资源
    最近更新 更多