HomeHome Flag of the Danes Flag of the United States of America

cURL Journal
Using cURL to make the world go around at danallen.com

October 25, 2009
By Dan Allen


Fake IT People, you can tell by their spiffiness. Even though they are fake, the large white board and
relaxed atmosphere are crucial to the best IT work.


Thanks to cURL, the Earth is turning again. I am grateful and relieved.

spinning Earth real time

Also thanks to cURL, the webcams are on at danallen.com. To see the latest soon to be defunct programmers work area, click here. Thank you

Here is the code for how the Earth gets spinning:




$dogTargetPage = 'http://www.fourmilab.ch/cgi-bin/Earth?imgsize=275&opt=-l&lat=55.0&ns=North&lon=60&ew=West&alt=30000&img=learth.evif';

// create curl resource
$ch = curl_init();

// set url
curl_setopt($ch, CURLOPT_URL, $dogTargetPage);

//return the transfer as a string
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

// $output contains the output string
$output = curl_exec($ch);

// close curl resource to free up system resources
curl_close($ch);


$dogSniffNose = strpos($output,'img src="/cgi-bin/Earth?di=');
$dogPicAddressStart = $dogSniffNose + 27;
$dogSniffTail = strpos($output,'"', $dogPicAddressStart);
$dogPicAddressEnd = $dogSniffTail;
$dogPicAddressLength = $dogPicAddressEnd - $dogPicAddressStart;
$dogPicHash = substr($output,$dogPicAddressStart,$dogPicAddressLength);
$dogPicURL = 'http://www.fourmilab.ch/cgi-bin/Earth?di=' . $dogPicHash;
?>



Next steps:

  1. Fix webcams that run with the spinning Earth at danallen.com DONE
  2. Replace live image link from danallen.com with cron job that saves updated pic once per 15 minutes. DONE
  3. Save those 15-minute pics for a year
  4. Use pics from file instead of Swiss Observatory, to achieve spin independence
  5. Be happy for being a step closer to fulfilling a dream

  6. October 2009
    The basic idea is to use cURL to read a webpage at the Swiss Earth Observatory, looking for the address of the earth image (sample), saving that address to a php variable that can then be used to display the latest live image on my website.

    To see what CURL is going to do, surf over to the Swiss Earth Observatory. When you get there, right click in the white area of the page, and select VIEW SOURCE. This will display the web page code sent to your browser. The browser translates this code on your computer into the web page you see. The picture of Earth at that page has an address that always changes. To see what it is now, scan down the screen displayed by view source until you find
    <img src="/cgi-bin/Earth?di=
    After the di=, there will be a long string of letters and numbers, that look something like this.
    E9B2DF0EAA864 48B20D6AB4ABD37D7605BB4A 684FEC0D8EB20EA5BAB710F335356 35B0DCF2B0D15E683658B6E75C4761D5C A004DFF5266CE5675B091
    That long string always changes. Curl can read the SOURCE for the web page, find the long string, and save it.

    Starting with an introduction from php.net
    Once you've compiled PHP with cURL support (comes with Linux hosting from Godaddy), you can begin using the cURL functions.

    The basic idea behind the cURL functions is that you initialize a cURL session using the curl_init(), then you can set all your options for the transfer via the curl_setopt(), then you can execute the session with the curl_exec() and then you finish off your session using the curl_close(). Here is an example that uses the cURL functions to fetch the example.com homepage into a file:
    $ch = curl_init("http://www.example.com/");
    $fp = fopen("example_homepage.txt", "w");

    curl_setopt($ch, CURLOPT_FILE, $fp);
    curl_setopt($ch, CURLOPT_HEADER, 0);

    curl_exec($ch);
    curl_close($ch);
    fclose($fp);
    ?>

   
Montpelier Websites' FAMOUS
Frequently Asked Questions


login



search
September 4, 2010 | 4:44 pm 61 °F
Montpelier, Vermont USA 44.26N 72.58W
G1 Endy Race 2 Lap 825
Last Lap  @robertwagnervt Volunteers called to build enthusiasm for November election, not #corruption #vtgov @BTV_Dems #VT go go go September 01, 2010 10:36:37 pm Driver's Condition: On time for fall
contact about music
Track News
edited by DAN ALLEN
New Host
Next Steps

Rather than relying on email for a task list that is changing all the time, I am keeping the next steps and status on this page.
By Dan Allen

Twitter

Replaces the byte as the smallest useful package of data

    follow

    Music
    Dan's Playlist


    By Various Artists

    Slow Is Fast
    Plugging Into Bedrock

    Even though immediate objectives are in sight, still necessary to delay speed for infrastructure development. In this case, infrastructure is spelled V-T-D-i-g-g-e-r.
    By Dan Allen

    VTDigger Story
    Smart Grid Over Broadband

    Assebling the pieces slowly in the Work Queue go go go

    What is AJAX Programming?
    AJAX is a special program for updating parts of a webpage. The benefit is that tiny parts of a web page can display changes without re-displaying the parts of the page that have not changed. Re-display forces the internet to carry mountains of data it already has delivered. AJAX lets the internet say: "Update this one part of the webpage, and leave everything else still."

    live earth with live webcams

    By Dan Allen

    Ferguson and the Montpelier 650

    Stephen Ferguson pays the freight, but is not allowed to drive. (Indy News Service)
    Stephen Ferguson grew up near the speedway. Even though he practically owns the team, team captain, Jimmy Glass, will not let him strap-on the car for a ride.
    By Tim Twinam, Montpelier Star

    Data Bridging
    data bridging at the Montpelier Worldwide Telecommunications Speedway
    Bridges only go in difficult spots, whether the bridge is for G1 Endy racing or data streams. In this Montpelier Telecommunications Super Speedway photo, data bridging is set in place during a driver rest period (August 2008). In the Boston area, data bridge work like this takes place under lights at night, to avoid disrupting traffic. Montpelier Speedway road crews have the relative luxury of working in the sunlight, kept cool by Green Mountain breezes.

    Moving data from one kind of software or database to another is difficult. Paste this web page, or even just a part of it, into Word, email, Excel, or almost any other program, and most likely what you get will be wild distortions of what you are looking at now.
    By Dan Allen

    Basic Racing Skills
    FTP

    File Transfer Protocol (FTP) is our friend in web racing.
    By Dan Allen

    Vermont Electric Running Super High Speed Broadband
    Over the next three years, Vermont's electric companies, through Velco and Vermont Transco LLC are installing super high bandwidth backbone for public use.

    From the Archive
    Allen's Beacon on Mount Everest Signals OK

    May 8, 2008 - As weather cleared on Mount Everest, a beacon signal from Dan Allen indicates all is well.

    Clear morning on Mount Everest
    By Anthony Vinsensen

    Lose Yourself
    If you had one shot, one opportunity, to seize everything you ever wanted, would you capture it?

    By Eminem

    Email Spam Filtering
    Sample solution, from the MIT Alumni Association
    By MIT Alumni Association

    overflow