PHP Weather Home Page

Caching the METARs

But you'll soon start to look for a way to improve the response-time of your script. To do this, you first have to decide what database you want to use. You have a number of options at this time:

A MySQL database

Set $useMySQL to 1, and then create a table with the following SQL statement:

CREATE TABLE metars (
  metar VARCHAR(255) NOT NULL,
  timestamp TIMESTAMP(14),
  station VARCHAR(4) NOT NULL,
  PRIMARY KEY (station),
  UNIQUE station (station)
);
A PostgreSQL database

Set $usePSQL to 1 and create a table with the following SQL statement:

CREATE TABLE metars (
  metar VARCHAR(255) NOT NULL,
  timestamp TIMESTAMP,
  station VARCHAR(4) PRIMARY KEY NOT NULL
);
An Oracle 8 database

Set $useOCI to 1 and create a table with this SQL statement:

create table metars (
  metar varchar2(255) not null,
  timestamp date,
  station varchar2(4)
);
alter table metars add primary key (station);
A DBM database

Set $useDBM to 1 and make make sure that the user running the webserver has write-permission to the current directory.

An XML file

Set $useXML to 1 and make sure that the webserver has read/write permission to the file cache.xml.

If you use a database that requires you to log on, then please remember to do so. There's already some code at the top of phpweather.inc that should serve as a guide.

If you don't connect to your database, you'll recieve a lot of errors, saying things like: "MySQL Connection Failed: Access denied for user: 'nobody@localhost' (Using password: NO) in phpweather.inc" and "Supplied argument is not a valid MySQL result resource in phpweather.inc". These errors are trying to tell you, that PHP Weather couldn't store the METAR in the MySQL-database, because you didn't supply a valid username and password. The errors will be similar for other databases.

If you've configured PHP Weather and the database correctly, PHP Weather will store the retrieved METARs in the database, and use the cached METAR if it's less that 1 hour old. If it's older, it is expected that the station has made a new observation, so we should update our data.


Warning: Cannot modify header information - headers already sent by (output started at /home/groups/p/ph/phpweather/htdocs/include/header.php:25) in /home/groups/p/ph/phpweather/htdocs/include/header.php on line 6

Fatal error: Cannot redeclare find_parents() in /home/groups/p/ph/phpweather/htdocs/include/navigation.php on line 83