WordPress.org

Ready to get started?Download WordPress

Forums

A fix for "failed to open stream" w/WeatherIcon 2.0 (2 posts)

  1. davidchait
    Member
    Posted 9 years ago #

    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);
    fclose($fp);
    }

    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...

  2. davidchait
    Member
    Posted 9 years ago #

    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.

    -d

Topic Closed

This topic has been closed to new replies.

About this Topic