Author Topic: PHP to make Metar placefiles...  (Read 17065 times)

0 Members and 1 Guest are viewing this topic.

Offline carterlake

  • Senior Contributor
  • ****
  • Posts: 243
    • CarterLake.org
PHP to make Metar placefiles...
« on: March 27, 2007, 09:13:45 PM »
Well it's not pretty (mainly because it works well enough for me) but for those who want to use METAR data in their maps, you can use this PHP code...

http://www.carterlake.org/metargrlevel3.php.txt

The data file I'm using is...

http://www.carterlake.org/metars.txt

The 2 on the end refers to which font size/style to use on the map so a person could display multiple sizes.

Which gives us this place file:

http://www.carterlake.org/metargrlevel3.php

If you know PHP, you can certainly use this to do all kinds of stuff.. displaying cloud cover or whatever. I'm happy with temperature.

I wouldn't suggest going crazy with displaying metars... probably something like 20 or so at most unless you CRON the data to your local server.

Here's my very very large list of metars:
http://members.cox.net/carterlakeweather/metars.txt

Davis VP2 6153; Weather Display (LIVE w/ Ajax); Quickcam for Notebooks Pro; Boltek w/ Nexstorm; GRLevel3; live NOAA Radio

Offline abrown

  • Member
  • *
  • Posts: 4
Re: PHP to make Metar placefiles...
« Reply #1 on: April 14, 2007, 08:18:23 PM »
I've been trying to get this script to work and hope someone can help me see what I'm missing.

I've used a few of CarterLake's PHP files and they work fine..but I've hit a snag with this one.

In GRLevel3, I add the url pointing to the php script as a place file on my server but...nothing.  Yes, the data file (metars.txt) is up on my server, too.

I keep thinking it's a path problem either to the php or to the metars.txt, but I've tried just about every combination I can and no joy.

Any help at all much appreciated.

Thanks,
Allen

Offline carterlake

  • Senior Contributor
  • ****
  • Posts: 243
    • CarterLake.org
Re: PHP to make Metar placefiles...
« Reply #2 on: April 14, 2007, 09:13:04 PM »
Ok, I found your script and metars.txt

It appears the script doesn't like the fopen part of the script.

Code: [Select]

$metarfilename = getenv('DOCUMENT_ROOT') . "/metars.txt";


Did you alter this line at all?

Davis VP2 6153; Weather Display (LIVE w/ Ajax); Quickcam for Notebooks Pro; Boltek w/ Nexstorm; GRLevel3; live NOAA Radio

Offline abrown

  • Member
  • *
  • Posts: 4
Re: PHP to make Metar placefiles...
« Reply #3 on: April 14, 2007, 09:53:19 PM »
Hi,

Here's the line cut and pasted:

$metarfilename = getenv('DOCUMENT_ROOT') . "/metars.txt";

Let me know if you need more info.  Thanks.

Allen

Offline carterlake

  • Senior Contributor
  • ****
  • Posts: 243
    • CarterLake.org
Re: PHP to make Metar placefiles...
« Reply #4 on: April 14, 2007, 09:56:07 PM »
Quote from: "abrown"
Hi,

Here's the line cut and pasted:

$metarfilename = getenv('DOCUMENT_ROOT') . "/metars.txt";

Let me know if you need more info.  Thanks.

Allen


Nope. That looks good.

Do you have an extra return at the end of metars.txt?

Davis VP2 6153; Weather Display (LIVE w/ Ajax); Quickcam for Notebooks Pro; Boltek w/ Nexstorm; GRLevel3; live NOAA Radio

Offline abrown

  • Member
  • *
  • Posts: 4
Re: PHP to make Metar placefiles...
« Reply #5 on: April 14, 2007, 10:40:31 PM »
Nope. metars.txt is clean.  
Thanks,
Allen

Offline carterlake

  • Senior Contributor
  • ****
  • Posts: 243
    • CarterLake.org
Re: PHP to make Metar placefiles...
« Reply #6 on: April 15, 2007, 07:54:31 AM »
Quote from: "abrown"
Nope. metars.txt is clean.  
Thanks,
Allen


Well... when I save it.. and run it... I get an error... but when I removed the extra return at the end... it works.

http://www.carterlake.org/test.txt  <- metars.txt
http://www.carterlake.org/test.php

Hey, yours is working now. Was it the extra return in metars.txt?

Davis VP2 6153; Weather Display (LIVE w/ Ajax); Quickcam for Notebooks Pro; Boltek w/ Nexstorm; GRLevel3; live NOAA Radio

Offline abrown

  • Member
  • *
  • Posts: 4
Re: PHP to make Metar placefiles...
« Reply #7 on: April 15, 2007, 10:31:49 AM »
I guess that was it!  It's running now.  Thanks for your help on this :D
(And thanks for the script!)
Allen

Offline carterlake

  • Senior Contributor
  • ****
  • Posts: 243
    • CarterLake.org
Re: PHP to make Metar placefiles...
« Reply #8 on: April 15, 2007, 12:32:38 PM »
Quote from: "abrown"
I guess that was it!  It's running now.  Thanks for your help on this :D
(And thanks for the script!)
Allen


Good!

Davis VP2 6153; Weather Display (LIVE w/ Ajax); Quickcam for Notebooks Pro; Boltek w/ Nexstorm; GRLevel3; live NOAA Radio

Offline hwky

  • Member
  • *
  • Posts: 4
Re: PHP to make Metar placefiles...
« Reply #9 on: December 04, 2007, 07:31:49 AM »
I would like to ask for some assistance in building a script to display metars. I would really like to parse the xml feed from the NWS.

Thanks in advance for the help. I am sort of new in building scripts, so any help would be greatly appreciated :)

hwky

Offline jmcmurry

  • Jim McMurry
  • Forecaster
  • *****
  • Posts: 528
  • Davis Vantage Pro 2 Plus Wireless.
    • Juneau County Weather
Re: PHP to make Metar placefiles...
« Reply #10 on: December 04, 2007, 08:32:59 AM »
Tom's script at the beginning of this thread is probably what you need.  The link to his example is broken, but if you click on the radar map in his signature, you can see what he's doing with it.

- Jim

Forum Search and Google Can be Your Best Friends

Offline MesquiteWx

  • Forecaster
  • *****
  • Posts: 610
    • Mesquite Weather
Re: PHP to make Metar placefiles...
« Reply #11 on: July 23, 2008, 12:30:04 AM »
I have tried running this and it won't load in GR3. When I tried to call the file directly it has an error.

http://www.mesquitechristmas.com/weather/metargrlevel3.php

Here is the metars file

http://www.mesquitechristmas.com/weather/metars.txt

I am not sure what to do next since their are no docs on this. Anyone running this know why it isn't working?

-Thanks

Offline Russell797

  • Senior Member
  • **
  • Posts: 81
    • Lowell Highlands Weather
Re: PHP to make Metar placefiles...
« Reply #12 on: August 31, 2009, 09:00:21 PM »
I have received this e-mail message from my web host:

---------------

Hi,

I want to notify you that your average CPU usage is very high for several weeks, and you need to optimize your software or move to another web host

lowellhi lowellhighlandsweather.com
Top Process %CPU 107 /usr/bin/php /home/lowellhi/public_html/metargrlevel3.php
Top Process %CPU 98.8 /usr/bin/php /home/lowellhi/public_html/metargrlevel3.php
Top Process %CPU 97.9 /usr/bin/php /home/lowellhi/public_html/metargrlevel3.php



wait for your feed back

Norman

---------

I have been forced to cease running the script on their server. I was loading 17 METARs, why would this be using excessive resources on the server in the form of cpu usage?

I'm I the first to report this problem?
Lowell Highlands Current Weather Conditions


Offline Russell797

  • Senior Member
  • **
  • Posts: 81
    • Lowell Highlands Weather
Re: PHP to make Metar placefiles...
« Reply #13 on: November 23, 2010, 10:53:45 PM »
I've been playing around trying to get this script to work on my local machines with no luck. The script runs perfectly well on my commercial web host, yet won't output anything when run on local servers such as xampp (php 5.3.1) or Abyss Web Server (php 5.2.8 ). I have tried making a few changes in php.ini to no avail, but I really don't know what I'm doing.

When executing the placefile http://localhost/metargrlevel3.php  in placefile manager I get this message after about 20 seconds..... ERROR: Unkown keyword on line 2......or nothing happens at all (no error message or anything, it just won't work) depending on php.ini settings. Sometimes, depending on settings,  it will freeze up the php time stamp placefile script I am running.

Every other script I have tried running within a web browser has worked flawlessly in these local environments. Any ideas what the problem might be?

Thanks

« Last Edit: November 30, 2010, 11:56:06 PM by Russell797 »
Lowell Highlands Current Weather Conditions


Offline ELDoradoWx

  • El Dorado Weather
  • Senior Contributor
  • ****
  • Posts: 298
  • Gentoo X = Complete_Control
    • El Dorado Weather
Re: PHP to make Metar placefiles...
« Reply #14 on: November 24, 2010, 05:27:17 AM »
I've been playing around trying to get this script to work on my local machines with no luck. The script runs perfectly well on my commercial web host, yet won't output anything when run on local servers such as Axampp (php 5.3.1) or Abyss Web Server (php 4.8.1). I have tried making a few changes in php.ini to no avail, but I really don't know what I'm doing.

When executing the placefile http://localhost/metargrlevel3.php  in placefile manager I get this message after about 20 seconds..... ERROR: Unkown keyword on line 2......or nothing happens at all (no error message or anything, it just work) depending on php.ini settings. Sometimes, depending on settings,  it will freeze up the php time stamp placefile script I am running.

Every other script I have tried running within a web browser has worked flawlessly in these local environments. Any ideas what the problem might be?

Thanks



I have it running on my Gr3 page when there is no rainfall in the area, so the temps don't interfere with the radar since it writes on top of the radar. 
http://www.eldoradocountyweather.com/grlevel3/grlevel3-radar.html

The script needs to be updated to correct a few bugs. I had to tweak a few things in the code to get it running properly on my site. The script belongs to Carter Lake and I don't know if he still supports it or not. It can be a bit tricky to get working. I've seen people experience an endless loop when running the script which I also ran into. I also had an issue with missing metar array data.

A few tips that will hopefully help you: Anyone trying to run the script should first fix the endless loop issue. I saw this happen every time it displayed errors. Another issue - sometimes it works and sometimes it doesn't. You can run it 5-10 times in a row with errors and on the 11th attempt it works perfectly with no errors. When launching the application give it a good 20 seconds to populate. If it doesn't populate close the program and launch it again. You could also do a test and have Gr3's placefile point to the metars.txt file, just so you can see that it does indeed work. The script as written needs to be run from the root directory.

As far as the error on line 2 - I believe that's an error from the Gr3 program trying to read the data from metars.txt, which is probably caused by a failed php script unless you have a syntax error or tweaked the metars.txt file from the original format.





-Danny
-root is everything

Offline DaculaWeather

  • WxElement panel
  • Forecaster
  • *****
  • Posts: 3206
    • North Georgia Weather
Re: PHP to make Metar placefiles...
« Reply #15 on: December 18, 2010, 02:25:07 PM »
Hey Danny, trying to get this working. I think I've done everything I'm suppose to do and GR3 doesn't give any errors but... no data.

Offline ELDoradoWx

  • El Dorado Weather
  • Senior Contributor
  • ****
  • Posts: 298
  • Gentoo X = Complete_Control
    • El Dorado Weather
Re: PHP to make Metar placefiles...
« Reply #16 on: December 18, 2010, 10:35:57 PM »
Hey Danny, trying to get this working. I think I've done everything I'm suppose to do and GR3 doesn't give any errors but... no data.

If you still want it, just email me and I'll send you the script with instructions..  8)
-Danny
-root is everything

Offline gulfbreeze

  • Member
  • *
  • Posts: 5
    • Waveland Weather Center
Re: PHP to make Metar placefiles...
« Reply #17 on: July 31, 2011, 02:30:10 PM »
Is there any sort of instructions as to go about using this place file or is it just hit and miss?  ](*,) 

I got the php file installed, and ran it, it produced the required file.  I copied and pasted it to a txt file using notepad.

I loaded it thru the placefile option, and presto I get the Temps...but here what I don't get or can't understand, how is the metar.txt file picked up by GR3? If it (the Metar.txt file) is on the server? I'm having to do it manually just to get it to work....is there a way to automate this, or did I completely miss something??? 

 :???:

GB

Thanks in advance for the help...
<a href="http://waveland-weather.org/">
<img src="http://waveland-weather.com/wxgraphic.php?type=banner"
alt="Current Weather Conditions in Waveland, MS"
title="Current Weather Conditions in Waveland, MS"
width="500" height="80" /></a>

Offline DaculaWeather

  • WxElement panel
  • Forecaster
  • *****
  • Posts: 3206
    • North Georgia Weather
Re: PHP to make Metar placefiles...
« Reply #18 on: July 31, 2011, 02:44:56 PM »
In the GRL3 Placefile, you can add a URL to a script on your site. The php file is what you point it to.

Offline gulfbreeze

  • Member
  • *
  • Posts: 5
    • Waveland Weather Center
Re: PHP to make Metar placefiles...
« Reply #19 on: July 31, 2011, 03:17:57 PM »
Done...Now I get the Temps, but they aren't updating?  :sad:

Update:
Ok I found the issue apparently my server didn't like the period before the slash mark in this statement.

$metarfilename = getenv('DOCUMENT_ROOT') . "./metars.txt";     

Took out the period before "/metars.txt"; and all is working!    =D&gt;

Thanks DraculaWx....

GB
« Last Edit: July 31, 2011, 04:12:51 PM by gulfbreeze »
<a href="http://waveland-weather.org/">
<img src="http://waveland-weather.com/wxgraphic.php?type=banner"
alt="Current Weather Conditions in Waveland, MS"
title="Current Weather Conditions in Waveland, MS"
width="500" height="80" /></a>

Offline Cynjut

  • Senior Member
  • **
  • Posts: 59
    • Bellevue, NE local weather
Re: PHP to make Metar placefiles...
« Reply #20 on: August 03, 2011, 04:17:23 PM »
Unless you're storing the metars.txt file in the root directory of your server (which is plausible), this shouldn't work.  On the other hand, the extra "." would work if the DOCUMENT_ROOT for your webserver is set correctly AND has a slash at the end. 

Generally, a "double slash" will be correctly interpreted as a single slash in a directory name, so "/var/www/html/" and "./whatever" should work as well as "/var/www/html" and "./whatever".  On the other hand, if your document root is set to "/var/www/html", the period will cause all kinds of problems.

If DOCUMENT_ROOT is not set at all, the "./" should open the file in whatever "root" directory the process is running, and there's no clean way of predicting that for all platforms.  Since the code is PHP, you could also be using the superglobal array $_ENV{"DOCUMENT_ROOT"} instead.  Since this doesn't (theoretically) rely on the underlying operating system call, you might get what you are looking for.

You could also change the code to "reasonableness" check the $_ENV{"DOCUMENT_ROOT"} variable's last character and make sure it's a "/".

Offline DaculaWeather

  • WxElement panel
  • Forecaster
  • *****
  • Posts: 3206
    • North Georgia Weather
Re: PHP to make Metar placefiles...
« Reply #21 on: November 16, 2011, 08:36:34 AM »
How would I display some of the other extracted data? Say dewpoint?