After I installed and setup this module (ICAO code: LDZA), I tried to enable the weather block, but it failed:

* warning: file_get_contents(ftp://weather.noaa.gov/data/observations/metar/stations/EDDH.TXT) [function.file-get-contents]: failed to open stream: Connection timed out in /myweb/modules/weather/weather.module on line 548.
* Download location for METAR data is not accessible.

Comments

toddy’s picture

Assigned: Unassigned » toddy
Priority: Critical » Normal

Hi,

on some rare occasions, the FTP site weather.noaa.gov is not responding. Do you still see this error? I can right now fetch the data just fine.

jazzitup’s picture

Still nothing... for LDZA, or LDZG now it returns:

* warning: array_merge() [function.array-merge]: Argument #2 is not an array in /myweb/modules/weather/icao_codes.inc on line 36.

Anonymous’s picture

Version: 4.7.x-1.x-dev » 4.7.x-2.0
Assigned: toddy »
Priority: Normal » Critical

I have the same problem in line 840 of the weather module. Version 4.7.x-2.0.

Message:
Warning: file_get_contents(ftp://weather.noaa.gov/data/observations/metar/stations/EHGG.TXT) [function.file-get-contents]: failed to open stream: Connection timed out in /home/mnadvies/public_html/drupal/modules/weather/weather.module on line 840

When I follow the link ftp://weather.noaa.gov/data/observations/metar/stations/EHGG.TXT in my browser, the text of the file EHGG.TXT (2006/11/16 01:25
EHGG 160125Z AUTO 18012KT 150V220 9999NDV NCD 11/09 Q1002) is shown.

Martin

scriptnews’s picture

Hi

Great module ... but

seems that I have the same problem.

On y server, I know that certain file fetch functions are disabled.

The solution to fetch files from other servers - like here - wouild be to do it either wget or cURL.

Would it be to hard to change or include different opions.

It might even be interesting to have the option to work with local files, ... ?

Just 2 cents.

Roland

frog’s picture

I also am on a server (Dreamhost) that disables certain file access functions. I searched on the error, and many other modules have this problem, too. Some have used CURL for a workaround solution. But I am not entirely sure how to implement it. Below is my error message:

* warning: file_get_contents() [function.file-get-contents]: URL file-access is disabled in the server configuration in /home/.furgie/emlast/sumterguide.goofyorgan.com/modules/weather/weather.module on line 569.
* warning: file_get_contents(ftp://weather.noaa.gov/data/observations/metar/stations/KSSC.TXT) [function.file-get-contents]: failed to open stream: no suitable wrapper could be found in /home/.furgie/emlast/sumterguide.goofyorgan.com/modules/weather/weather.module on line 569.
* Download location for METAR data is not accessible.

toddy’s picture

Title: Failed to open stream » Provide alternative download machanisms like CURL
Assigned: » toddy
Category: bug » feature
Priority: Critical » Normal

Hi,

thanks for the suggestion, I'll look into implementing CURL for getting the data. However, if the PHP installation you're working with is really strict about outgoing connections, I'm afraid that no solution will possibly make the module work. Nevertheless, alternative download mechanisms are surely worth being implemented. Stay tuned.

Regards,
Tobias

toddy’s picture

Title: Provide alternative download machanisms like CURL » Provide alternative download mechanisms like CURL
toddy’s picture

Status: Active » Fixed

I've modified the module to only use the current download mechanism if it's really available. As an alternative approach, the module tries to use CURL if that's available. If both functions are not provided by your PHP installation, it fails with the message that the download location is not available.

Please download and test weather-4.7.x-2.1. Unfortunately, I cannot test the CURL functions myself. I'd appreciate feedback if the CURL implementation works for you.

Regards,
Tobias

Anonymous’s picture

Assigned: toddy »
Priority: Normal » Critical
Status: Fixed » Active

A fast test:

The same error in Version 2.0:

Warning: file_get_contents(ftp://weather.noaa.gov/data/observations/metar/stations/EHGG.TXT) [function.file-get-contents]: failed to open stream: Connection timed out in /home/mnadvies/public_html/drupal/modules/weather/weather.module on line 857

toddy’s picture

Assigned: » toddy
Priority: Critical » Normal
Status: Active » Fixed

Version 2.0 does not support CURL. Please use version 2.2, which supports CURL and wget.

jazzitup’s picture

Version: 4.7.x-2.0 » 4.7.x-2.1
Category: feature » bug
Status: Fixed » Active

I've tried v2.1 (the link you provided here), but the module failed to create a table "weather_config", so I've created it manually (I blame '{' and '}' around the table name within the file weather.install).

After I selected my hometown on administer > weather, I went to administer > blocks to enable the block. I've found two disabled blocks:
Custom user weather
System-wide weather

My 2 cents
I wouldn't recommend those names, because of usability (ability to quickly locate the blocks of the weather module, ordered alphabetically within the list of other modules), so I suggest these names:
Weather: custom user
Weather: system-wide

After I tried to enable "Custom user weather" block, the block doesn't appear on my site and when I tried to enable block "System-wide weather" block, my browser tried to fetch the data with no success (more than 2min. of delay).

The warning message:

* warning: file_get_contents(ftp://weather.noaa.gov/data/observations/metar/stations/LDZA.TXT) [function.file-get-contents]: failed to open stream: Connection timed out in /mysite/modules/weather/weather.module on line 857.
* Download location for METAR data is not accessible.
* user warning: Unknown column 'next_update_on' in 'field list' query: UPDATE weather SET next_update_on=1163715856 WHERE icao='LDZA' in /mysite/includes/database.mysql.inc on line 120.
Anonymous’s picture

Version: 4.7.x-2.1 » 4.7.x-2.2
Priority: Normal » Critical

After reinstalling version 2.2 and reinstalling de 2 database tabels the following error is displayed after installing a block of the weather module:

Warning: file_get_contents(ftp://weather.noaa.gov/data/observations/metar/stations/EDDH.TXT) [function.file-get-contents]: failed to open stream: Connection timed out in /home/mnadvies/public_html/drupal/modules/weather/weather.module on line 850

Martin

toddy’s picture

Reading the error message, it looks like your PHP installation is able to use file_get_contents() with an outside URL. However, the fetching fails for some different reason. Can you actually use any other module with tries to fetch data from outside sources? It looks to me like a problem with your setup. Maybe you're behind a firewall or something which blocks these requests?

Anonymous’s picture

Let's first say: I am absolute not an php expert!!

Yesterday I tested the script for fetching the METAR data. In the weather module I changed the script from line 847 til the command text "//check on errors".

I have BlueHost as hosting provider, and my phpinfo() says that curl is installed.

CURL support 	enabled
CURL Information 	libcurl/7.15.3 OpenSSL/0.9.7a zlib/1.2.1.2 libidn/0.5.6

I know that Blue host has a firewall installed. A test with cgi-bin/firewal gives:

Firewall/Proxy Test
 80 HTTP 
 20/21+Data FTP 
 2082 cPanel 
 2095 Webmail 
 443 SSL HTTP 
 465 SSL SMTP 
 995 SSL POP 
 993 SSL IMAP 
 2083 SSL cPanel 
 2096 SSL Webmail 

I also have Google maps and Google Ads installed and working. So there is communication to the outside www.

Test:

//  if (function_exists('file_get_contents') and ini_get('allow_url_fopen')) {
//    $metar_raw = file_get_contents($url);
//  } else if (function_exists('curl_init')) {
//    $curl = curl_init($url);
//    curl_setopt($curl, CURLOPT_TRANSFERTEXT, TRUE);
//    curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
//    $metar_raw = curl_exec($curl);
//    curl_close($curl);
//  } else if (function_exists('exec')) {
//    exec("wget --quiet -O- $url", $output, $return_val);
//    if ($return_val == 0) {
//      $metar_raw = join("\n", $output);
//    }
//  }

$curl = curl_init();
   curl_setopt($curl, CURLOPT_TRANSFERTEXT, TRUE);
   curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
   $metar_raw = curl_exec($curl);
curl_close($curl);

//if (function_exists('exec')) {
//    exec("wget --quiet -O- $url", $output, $return_val);
//} else  if ($return_val == 0) {
//      $metar_raw = join("\n", $output);

Result:Error message: Download location for METAR data is not accessible.
IMO: $metar_raw === false.

I changed: $curl = curl_init(); to $curl = curl_init($url): same bad result.

My test site is www.evenementen.steb.nl. The module is installed at this moment.

toddy’s picture

Hm, maybe the FTP access is somehow blocked by your provider, I don't know. There's still a small chance to get this module working. Could you please replace the entire function _weather_retrieve_data() with the following code snippet? It tries to get the METAR data via HTTP POST, not FTP. If this does not work out, I'm afraid I have no more ideas how to resolve your problem.

function _weather_retrieve_data($icao) {
  $icao = strtoupper($icao);

  $metar_raw = FALSE;
  // if the FTP access does not work, try POSTing the ICAO via HTTP
  if ($metar_raw === FALSE) {
    if (function_exists('fsockopen')) {
      $handle = fsockopen('weather.noaa.gov', 80);
      if ($handle !== FALSE) {
        $request = "POST /cgi-bin/mgetmetar.pl HTTP/1.1\r\n";
        $request .= "Host: weather.noaa.gov\r\n";
        $request .= "Content-Type: application/x-www-form-urlencoded\r\n";
        $request .= "Content-Length: 9\r\n\r\n";
        $request .= "cccc=$icao\r\n";
        fwrite($handle, $request);
        while (!feof($handle)) {
          $response .= fgets($handle, 1024);
        }
        fclose($handle);
        // extract the valid METAR data from the received webpage
        if (preg_match("/($icao [0-9]{6}Z .+)/", $response, $matches)) {
          $metar_raw = $matches[1];
        }
      }
    }
  }

  // check on errors
  if ($metar_raw === FALSE) {
    drupal_set_message(t('Download location for METAR data is not accessible.'), 'error');
  }

  return $metar_raw;
}
Anonymous’s picture

YES: you are perfect!! Thanks

toddy’s picture

Status: Active » Fixed

Good to hear :-)

I'll release a new version of the module shortly, which will also support different images for day and night.

Regards,
Tobias

Anonymous’s picture

Status: Fixed » Closed (fixed)
frog’s picture

The CURL fixes a lot of my problems. Thanks so much! Now, if I could only get weather outside of Germany.

shaileshtr’s picture

I am too seeing the error. When open the link http://www.freefblike.com I get this error from a week. I don't know what happened with the codes, because it was unaltered from lat perfect run. Please if anybody could solve the problem. Regards!