Support » Plugins and Hacks » A fix for “failed to open stream” w/WeatherIcon 2.0

A fix for “failed to open stream” w/WeatherIcon 2.0

  • With new WP, there’s a built-in function to retrieve a given URI. My quick fix was to use that, as it will use fopen if available, else use curl.

    look for the lines:

    $host = 'weather.noaa.gov';
    $location = "/pub/data/observations/metar/stations/$station.TXT";

    You’ll be replacing all the code AFTER those two variables, all the way down to (but not including):

    if ($fp = fopen($metar_cache, "w"))
    fwrite($fp, $metar);

    The new, replacement quick hack retrieval code I used is:

    $metar = wp_remote_fopen('http://'.$host.$location);
    $offset = strpos($metar, $station); // better be!
    if ($offset===FALSE) $metar = false;
    else $metar = substr($metar, $offset);

    Seems to be working well for me so far at home, though my host still doesn’t like curl any better than fopen/fsockopen.

    THIS IS A HACK. YMMV. If you aren’t having problems, I’d wait until it can be tested further and rolled into a ‘proper’ bulletproof solution in a main release…

Viewing 1 replies (of 1 total)
  • for my site, I had to actually use my cgurl retrieval class, which uses sockets directly. fopen, fsockopen, and curl all just hung up on me for minutes at a time…

    but otherwise, the above ‘process’ seems to work well.


Viewing 1 replies (of 1 total)
  • The topic ‘A fix for “failed to open stream” w/WeatherIcon 2.0’ is closed to new replies.
Skip to toolbar