3

I am trying to integrate a wget command I have written into a php script. The command recursively downloads every html/php file on a website (which is required functionality that I haven't found in file_get_contents()). I have tested the wget command in a terminal window, but when executing it using either exec() or shell_exec() nothing happens. I don't get any errors, or warnings.

Here is the command in question,

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

I have tried simple wget commands (not as many parameters) from exec(), and shell_exec(), but they also don't work.

If wget isn't an option, I am open to using some other method of downloading a website in it's entirety.

My code that I have now is,

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

Then when printing the array it is empty

Jfonts
  • 63
  • 2
  • 8

3 Answers3

2

I had to specify a path to wget. New command:

exec("/usr/local/bin/wget google.com", $array);
Jfonts
  • 63
  • 2
  • 8
  • make use $return_var to check about that. If not 0, then something went wrong. –  May 08 '16 at 18:07
1

invoke wget with proper options

-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);'
0

In our case wget didn't have enough permission to save wget'ed file in current dir. Solution:

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

where

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

ps. we also added /usr/bin found with whereis wget but in our system it works fine without it

vladkras
  • 16,483
  • 4
  • 45
  • 55