Many thanks to all (especially Brad) for your input on this.
Although I have not got as far as producing PDFs I have managed to implement
output buffering and saving of generated pages under a hashed name, and of
course retrieving it instead of doing all the queries again. I've trimmed
slightly the code below as I do some trimming of the session contents before
hashing. I also have to work out how to handle some functionality that uses
session data, so will probably generate a 'hashed' csv file along with the
html file.
For those that are interested (if only to comment on my coding skills !!)
what I have done is:
( It may not be pretty but it seems to work )
page1.php
---------
<?php
session_start();
include("includes/staticHtml.inc.php");
if ($_SERVER['QUERY_STRING'])
$to_hash = $_SERVER['PHP_SELF'].$_SERVER['QUERY_STRING'];
else
$to_hash = $_SERVER['PHP_SELF'];
$static = new static_html($to_hash);
if ($static->status == 'new') // Did not exist
{
ob_start(); // Start output buffering
}else{
echo $static->html;
exit();
}
... query processing etc ...
$str = ob_get_contents();
$static->save_html($str);
ob_flush();
?>
staticHtml.inc.php
------------------
<?php
class static_html {
var $status;
var $html;
var $hash;
var $static_path;
var $path;
function static_html($fullUrl) {
$this->$static_path = "../static/";
$ssn = implode('_',$_SESSION);
$this->hash = md5($fullUrl.$ssn);
$this->path = $this->$static_path.$this->hash.'.htm';
$this->find_html();
}
function find_html() {
if (file_exists($this->path))
{
$this->html = file_get_contents($this->path);
$this->status = 'old';
}else{
$this->status = 'new';
}
}
function save_html($str) {
if ($this->find_html() == 'old')
{
// replace static page??
}else{
$fp = fopen($this->path,'w');
$sts = fwrite($fp,$str);
fclose($fp);
}
}
}
?>
-----Original Message-----
From: Brad Pauly [mailto:[EMAIL PROTECTED]
Sent: 23 September 2004 23:36
To: Php-General
Subject: Re: [PHP] Re: PDF from PHP generated HTML, possible?
On Thu, 23 Sep 2004 22:39:06 +0100, Graham Cossey
<[EMAIL PROTECTED]> wrote:
>
> Brad: When you say "a hash of the query string" do you mean passing the
> variable part of the URL thru mhash to obtain a hash/key/digest or
whatever
> you wish to call it? If so, do you recommend any particular hash, ie MD5,
> GOST or TIGER? Not knowing much about these things, I imagine passing the
> same text thru a given hash algorithm multiple times will always return
the
> same result.
I tend to use md5, but the other hash functions ought to work too. I
don't know about GOST and TIGER, but I know php has support for SHA1
and another that I don't remember at the moment.
> So:
>
> Requested URL
> http://server/app/page1.php?cust=12345&t=3
>
> Variable part hashed
> page1.php?cust=12345&t=3 > hash > mdg4789gnvh095n
>
> If the following URL exists use it, otherwise do processing, get buffer
and
> write to this file.
> http://server/app/static/mdg4789gnvh095n.html
Yep. I would check for the file (or whatever mechanism you use to
store the cache) instead of the URL. You could write a class or a few
functions that could do this check for you based on the hash.
> If PDF of page requested:
> Send the current URL (http://server/app/static/mdg4789gnvh095n.html)
through
> pdf-o-matic or similar.
You might consider creating the pdf version at the same time you
create the html. I depends on how your app works. Can you request a
pdf before you reque
> Is that about right?
Yep. I think you've got it.
> Many thanks
No problem =)
- Brad
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php