0

Hi I am trying to execute wget locally using cron, I have been told by my hosting that due to a local loopback that this won't work?

I am attempting the following command:

wget -q -O /pathtofile/blah.xml "http://myurl/myfeed.php?id=26"

What I am trying to do here is take the output (rss) and save this on my webserver as xml, the way I have been doing this is to open the url and save the source to xml and upload, so I would like to automate this.

Error text:

--12:38:58-- http://www.myurl.com/mydir/myfeed.php?id=26
=> `myfeed.php?id=26'
Resolving www.myurl.com... myip
Connecting to www.myurl.com|myip|:80... failed: Connection refused. 

Is there any thing I can do to achieve this?

Dennis Williamson
  • 60,515
  • 14
  • 113
  • 148

3 Answers3

0

If you can modify myfeed.php to take command line variables as well as $_POST/$_GET then you can just execute PHP from cron:

php /path/to/myfeed.php --id=26

See here for more info on passing args to command line PHP.

You will need to do something like this at the top of your file:

define('CLI', php_sapi_name() == 'cli');

if(CLI){
   $input =& $argv;
}else{
  $input =& $_POST;
}

if(isset($input['id'])) // etc...
beggs
  • 386
  • 2
  • 9
0

It will work if:

  1. Your web-server is listening on the local interface; and
  2. Your /etc/hosts file has www.myurl.com pointing to the local IP.

Otherwise, it will fail. If you can do a netstat -untap and confirm that your web-server is listening on the local interface, it should work.

sybreon
  • 7,357
  • 1
  • 19
  • 19
0

you can also try to use the --bind-address option.

  --bind-address=ADDRESS
       When making client TCP/IP connections, bind to ADDRESS on the local machine. ADDRESS may be specified as a hostname or IP
       address.  This option can be useful if your machine is bound to multiple IPs.

and bind to the external ip, instead of the local one.

Drakonen
  • 104
  • 5
  • Hi Thanks this is almost working, I get the default RSS but the bind is dismissing the php id variable any ideas? /usr/bin/wget -q -O blah.xml --bind-address=127.0.0.1 "http://www.myurl.com/mydir/myfeed.php?id=26" –  Sep 09 '09 at 13:06