PHP Script - RealTimeLog
This is a first shot at a script to collect the realtime.txt data that is uploaded to a website so that you can use historical data.
Basically what this script does is each time it is run, it looks at the contents of the current realtime.txt file and saves it to a logfile called realtime.log.
It slightly changes the date field so that is uses and ISO date format which is sortable. This is useful for keeping the data in order for more advanced functions.
The data that is stored is what is contained within the realtime.txt file.
This should work on any PHP5 based Unix web server. I have not tested it on a Windows based PHP5 server and I really don't know much about IIS with PHP installed.
Ideally, this script needs to run once a minute. This can best be achieved by using cron (Crontab) on the web server. Most Unix based Web Servers and ISP's support this type of function. If not, there are a few options:
1) use something like Pseudo-Cron. This works okay if your website has a lot of traffic. If it doesn't, then you will easily miss the 1 minute increments.
2) Execute the script remotely using your workstation. Unfortunately, this is not a function within Cumulus, but you could schedule the calling of the script via the net. I don't have specifics on how to do this... but if someone needs it, I'm sure it can be found quickly enough. Of course this means your computer needs to be on (Cumulus as well)....
Another issue is that Cumulus needs to be uploading the realtime.txt file. It should be uploading it at least once a minute. Any faster than that won't matter much.
Configuration
Some is needed....
Code: Select all
$SITE['home'] = "YOU MUST SET THIS";
$SITE['datafile'] = "realtime.log";
$SITE['source'] = "realtime.txt";
The Datafile variable should be okay... Most of the other scripts that will use this data will be setup to use the log as that where it is.
Same for the source variable. If this script is loaded on your server in the same location as where the realtime.txt file is uploaded to, you won't need to change it.
You MUST create the data file
In order for this script to work, the datafile MUST existing and it MUST have 0666 (rw-rw-rw) permissions. This would be
Code: Select all
chmod 0666 realtime.log
You might need to chmod the script realtimelog.php as well to something like chmod 0755.
Setting up the Cron Entry
As mentioned above, the best way to execute this would be via cron.
A typical crontab entry for this script would be:
Code: Select all
* * * * * /path_to_php_cli/php /path_to_your_webroot/realtimelog.php > /dev/null 2>&1
Source Code:
TNET Cumulus Project Page
What the logfile will look like:
Almost like the realtime.txt file except that it will have a changed date field and it will contain an ever growing number of entries which will be the historical information of your site.
Sample:
Code: Select all
2008-10-11 09:15:16 12.2 94 11.3 7.7 7.8 231 0.0 14.6 1019.1 SW 3 kts
2008-10-11 09:16:16 12.2 94 11.3 8.2 6.1 232 0.0 14.6 1019.1 SW 3 kts
2008-10-11 09:17:16 12.2 94 11.3 9.6 12.2 244 0.0 14.6 1019.2 WSW 3 kts
2008-10-11 09:18:16 12.2 94 11.3 11.3 5.2 218 0.0 14.6 1019.2 SW 4 kts
2008-10-11 09:19:16 12.2 94 11.3 10.1 6.1 248 0.0 14.6 1019.1 WSW 3 kts
2008-10-11 09:20:16 12.2 94 11.3 9.0 10.4 225 0.0 14.6 1019.1 SW 3 kts
2008-10-11 09:21:16 12.2 94 11.3 9.8 6.1 240 0.0 14.6 1019.2 WSW 3 kts
2008-10-11 09:22:16 12.2 94 11.3 10.9 11.3 235 0.0 14.6 1019.3 SW 4 kts
2008-10-11 09:23:16 12.3 94 11.4 12.0 13.9 242 0.0 14.6 1019.3 WSW 4 kts
2008-10-11 09:24:16 12.3 93 11.2 12.6 9.6 245 0.0 14.6 1019.3 WSW 4 kts
2008-10-11 09:25:16 12.3 93 11.2 12.7 13.0 243 0.0 14.6 1019.3 WSW 4 kts
2008-10-11 09:26:16 12.3 93 11.2 12.1 9.6 230 0.0 14.6 1019.2 SW 4 kts
2008-10-11 09:27:16 12.3 93 11.2 11.5 9.6 244 0.0 14.6 1019.2 WSW 4 kts
2008-10-11 09:28:16 12.3 93 11.2 11.8 7.8 244 0.0 14.6 1019.2 WSW 4 kts
2008-10-11 09:29:16 12.3 93 11.2 11.9 8.7 240 0.0 14.6 1019.2 WSW 4 kts
2008-10-11 09:30:16 12.3 93 11.2 10.5 8.7 235 0.0 14.6 1019.2 SW 3 kts
2008-10-11 09:31:16 12.3 93 11.2 9.4 8.7 235 0.0 14.6 1019.2 SW 3 kts
2008-10-11 09:32:16 12.3 93 11.2 9.3 7.0 236 0.0 14.6 1019.3 SW 3 kts
2008-10-11 09:33:16 12.3 93 11.2 9.1 8.7 240 0.0 14.6 1019.3 WSW 3 kts
2008-10-11 09:34:16 12.3 93 11.2 10.2 9.6 236 0.0 14.6 1019.3 SW 3 kts
2008-10-11 09:35:16 12.2 93 11.1 12.4 6.1 243 0.0 14.6 1019.3 WSW 4 kts
2008-10-11 09:36:16 12.2 93 11.1 12.9 8.7 244 0.0 14.6 1019.3 WSW 4 kts
This script if called with debug will output debug information which might help if you are having problems.
Call the script like
Code: Select all
http://YOURWEBSERVER/realtimelog.php?debug
Code: Select all
DEBUG MODE ON
Current directory is: /opt/coolstack/apache2/vhosts/cumulus
Changing directory to: /www/vhosts/cumulus
Current directory is: /opt/coolstack/apache2/vhosts/cumulus
Attempting to load: realtime.txt
We loaded: 1 - Should be 1
Saving Data as: 2008-10-11 01:43:19 65.1 37 38.2 0.0 0.0 258 0.00 0.00 1001.8 WSW 0 mph
COMPLETE