Forum Moderators: coopster

Message Too Old, No Replies

Caching a Database Report

         

Frank_Rizzo

11:40 pm on Jan 12, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have a form which queeries a database and produces a report in a pop up window. This works fine but I think I can cache it by saving the report on the first run and then checking if the file exists on subsequent runs.

The problem I have is that I don't know how to save the report.

1. User chooses report option.
2. When Search clicked, PHP checks the URL string for the cache name.
3. If a static file with cache name exists the file is displayed in the pop up window
4. If the file does not exist the report is generated, displayed in the pop up window and saved as a static file.

<form....
javascript:popupreport"http://www.widgets.co.uk/php/search.php?report=widgets&cache_name=widgets12jan04")

search.php ...
if (file_exists($cache_name)) {
include($cache_name);
} else {
mysql search database...
display report..., save report...
}

I haven't tested this yet but I'm sure the include in the pop up window will work.

What' I'm not sure is the save report.

The display report just writes <html>...<table>... etc. so how do I get that page to save as the cache file name?

ergophobe

12:28 am on Jan 13, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I think you can solve your problem very easily just by changing the order of things a bit. Don't create the static page from your output, but create your output from the static page.

if (!file_exists($cache_name)) {
mysql search database...
save report as file $cache_name
}
include($cache_name);

Frank_Rizzo

10:16 am on Jan 13, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sleeping on it, I have worked out a better idea.

Because there can only be 10 reports each day, I can auto generate the files at midnight. There is then no need to generate the report on the fly because it had already been generated.

I can then just open the report in a popup window.

So all I need to do is to run the report in a php batch command line.

server>php search.php?report=widgets >widgets12jan04.html

This runs the database search and saves the outputted file to the cache_name.

But I can't do this on the server. It's Linux and it doesn't recognise / have the PHP executable?

Is there another way around this? I can set up a html page with the queeries all set on a page but that then would require a manual press of a submit button.

[edited by: Frank_Rizzo at 10:24 am (utc) on Jan. 13, 2004]

Frank_Rizzo

10:22 am on Jan 13, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have found out how to install PHP as a CGI. I'm a bit aprehensive about doing it though as I don't want to screw up what's already working. :{

dcrombie

1:52 pm on Jan 13, 2004 (gmt 0)



Use "wget" or "curl" to access the PHP page in your crontab or cron.daily.