Sunday, January 16, 2011

WGET Localhost 0 bytes

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?

  • 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...
    
    From beggs
  • 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.

    From sybreon
  • 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.

    From Drakonen

0 comments:

Post a Comment