I took the liberty of moving your question from the European forum into Server Side Scripting, in the belief that
a) the solution lies within this field and
b) the people who frequent this forum will find it easy and have an answer right away. (I will be keeping an eye on them on your behalf though, just in case.)
One thought that crossed my mind is that if you base your site on ODP data, rather than on your own db, then the free ODP++ program happens to have exactly what you want, built in from the start. It can be downloaded from www.portalscripts.com.
#!/usr/bin/perl
open(FP,"query.log");
chomp(@lines=<FP>);
close(FP);
@lines=reverse(@lines);
for ($i=0;$i < 10;$i++) {
print "$lines[$i]<br>";
}
exit;
Note: this won't scale well as it reads the whole log file into memory every time it runs. If you use this method I'd advise you keep a close eye on logfile size...
Any ideas for a more scalable solution anyone?
Log them to two files. The one is your "keeper" file to save for data storage and the other will be your "spy" file to view in real time.
#!/usr/bin/perl
open(FP,"spy.log");
chomp(@lines=<FP>);
close(FP);
open(FILE,">spy.log")
@lines=reverse(@lines);
for ($i=0;$i < 10;$i++) {
print "$lines[$i]<br>";
print FILE "$lines[$i]\n";
}
close FILE;
exit;
Nice idea...
The script has a gotcha though - the reverse(@lines) will constantly flip-flop the order of the lines, and the last 10 entries won't be preserved.
#!/usr/bin/perl
open(FP,"+<spy.log");
flock FP,2;
chomp(@lines=<FP>);
$count=$#lines;
truncate FP,0;
seek FP,0,0;
for ($i=($count-9);$i <= $count;$i++) {
print "$lines[$i]<br>";
print FP "$lines[$i]\n";
}
close(FP);
exit;