从 exec() 或 shell_exec() 调用时 wget 不工作
wget not working when called from exec() or shell_exec()
我正在尝试将我编写的 wget 命令集成到 php 脚本中。该命令递归下载网站上的每个 html/php 文件(这是我在 file_get_contents() 中未找到的必需功能)。我已经在终端 window 中测试了 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);
然后打印数组时它是空的
使用适当的选项调用 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);'
我必须指定 wget 的路径。新命令:
exec("/usr/local/bin/wget google.com", $array);
在我们的例子中,wget
没有足够的权限在当前目录中保存 wget'ed 文件。解决方案:
$dir = __DIR__.'/777folder/';
exec("/usr/bin/wget -P ".$dir." --other-options");
哪里
-P, --directory-prefix=PREFIX save files to PREFIX/...
ps。我们还添加了 /usr/bin
found with whereis wget
但在我们的系统中没有它也能正常工作
我正在尝试将我编写的 wget 命令集成到 php 脚本中。该命令递归下载网站上的每个 html/php 文件(这是我在 file_get_contents() 中未找到的必需功能)。我已经在终端 window 中测试了 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);
然后打印数组时它是空的
使用适当的选项调用 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);'
我必须指定 wget 的路径。新命令:
exec("/usr/local/bin/wget google.com", $array);
在我们的例子中,wget
没有足够的权限在当前目录中保存 wget'ed 文件。解决方案:
$dir = __DIR__.'/777folder/';
exec("/usr/bin/wget -P ".$dir." --other-options");
哪里
-P, --directory-prefix=PREFIX save files to PREFIX/...
ps。我们还添加了 /usr/bin
found with whereis wget
但在我们的系统中没有它也能正常工作