RE: Caching query results in html pages

RE: Caching query results in html pages

am 13.03.2007 14:18:13 von Bastien Koert

you can write an html page on the fly and save that to the hard drive

have a look at fopen/fwrite etc

bastien

>From: Vincent
>Reply-To: Vicente
>To: php-db@lists.php.net
>Subject: [PHP-DB] Caching query results in html pages
>Date: Tue, 13 Mar 2007 14:20:58 +0100
>
>Hi all,
>
>I'm trying to improve the performance for visitors, and I want to know
>if there is some way to store the mySQL results of .php scripts in
>webpages.
>
>So, in example, when requesting
>http://www.mydomain.com/script.php?id=110 , it can be redirected to
>his cached version http://www.mydomain.com/id110.html.
>
>
>Any code or information would be appreciated,
>
>
>Regards,
>
>--
>PHP Database Mailing List (http://www.php.net/)
>To unsubscribe, visit: http://www.php.net/unsub.php
>

____________________________________________________________ _____
Don’t waste time standing in line—try shopping online. Visit Sympatico / MSN
Shopping today! http://shopping.sympatico.msn.ca

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Caching query results in html pages

am 13.03.2007 14:20:58 von Vicente

Hi all,

I'm trying to improve the performance for visitors, and I want to know
if there is some way to store the mySQL results of .php scripts in
webpages.

So, in example, when requesting
http://www.mydomain.com/script.php?id=110 , it can be redirected to
his cached version http://www.mydomain.com/id110.html.


Any code or information would be appreciated,


Regards,

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re[2]: Caching query results in html pages

am 13.03.2007 18:41:42 von Vicente

Bastien wrote:

BK> you can write an html page on the fly and save that to the hard drive
BK> have a look at fopen/fwrite etc

And a more elaborated thing?. Some source development?

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

RE: Re[2]: Caching query results in html pages

am 13.03.2007 20:03:24 von Bastien Koert

http://www.weberdev.com/get_example-4082.html

>From: Vincent
>Reply-To: Vincent
>To: php-db@lists.php.net
>Subject: Re[2]: [PHP-DB] Caching query results in html pages
>Date: Tue, 13 Mar 2007 18:41:42 +0100
>
>Bastien wrote:
>
>BK> you can write an html page on the fly and save that to the hard drive
>BK> have a look at fopen/fwrite etc
>
>And a more elaborated thing?. Some source development?
>
>--
>PHP Database Mailing List (http://www.php.net/)
>To unsubscribe, visit: http://www.php.net/unsub.php
>

____________________________________________________________ _____
Have Some Fun Out Of The Sun This March Break
http://local.live.com/?mkt=en-ca/?v=2&cid=A6D6BDB4586E357F!1 42

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Caching query results in html pages

am 13.03.2007 23:24:40 von Micah Stevens

This may work, although I just made it up. I can see already that you'd
have some problems with multiple scripts running at once. If a script
opens the cache, then a second script saves new cache information before
the first script saves it's data, the first script would overwrite the
second script's update.

Maybe instead of a read at the beginning of script execution, a read at
the beginning of each query would be better?

Save cache results to a file:

// script start
$querycache = unserialize(file_get_contents("query.cache"));

/*
$querycache format:

array('sql' => array(), 'result'=>array(), 'time'=>array());

For each sql statement 'sql' you have a result array.
*/
// run all your queries through a function:
function query($sql) {
$cached = array_search($sql, $querycache['sql'])
// check to see if the result is old
if (time() - $querycache['time'][$cached] > $max_time) {
unset($querycache['time'][$cached]);
unset($querycache['sql'][$cached]);
unset($querycache['result'][$cached]);
$cached = false;
}
if ($cached) {
return $querycache['result'][$cached];
} else {
$result = mysql_query($sql);
$querycache['sql'][] = $sql;
$index = array_search($querycache['sql']);
$querycache['time'][$index] = time();
while ($r = assoc($result)) {
$querycache['result'][$index][] = $r;
}
// save cache for other scripts
file_put_contents('query.cache', serialize($querycache));
return $querycache['result'][$index];
}
}

.... It's actually kind of a complicated process now that I'm thinking
about it.

-Micah





On 03/13/2007 06:20 AM, Vincent wrote:
> Hi all,
>
> I'm trying to improve the performance for visitors, and I want to know
> if there is some way to store the mySQL results of .php scripts in
> webpages.
>
> So, in example, when requesting
> http://www.mydomain.com/script.php?id=110 , it can be redirected to
> his cached version http://www.mydomain.com/id110.html.
>
>
> Any code or information would be appreciated,
>
>
> Regards,
>
>

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Caching query results in html pages

am 15.03.2007 08:06:09 von Amit Patel

------=_Part_68898_32075225.1173942369652
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

I believe a much better solution would be to use MySQL Query Cache.
http://dev.mysql.com/doc/refman/5.0/en/query-cache.html

Use it wisely and there is a lot of performance gain. Donot simply enable
cache for all sql statements.

Amit.

On 3/13/07, Micah Stevens wrote:
>
> This may work, although I just made it up. I can see already that you'd
> have some problems with multiple scripts running at once. If a script
> opens the cache, then a second script saves new cache information before
> the first script saves it's data, the first script would overwrite the
> second script's update.
>
> Maybe instead of a read at the beginning of script execution, a read at
> the beginning of each query would be better?
>
> Save cache results to a file:
>
> > // script start
> $querycache = unserialize(file_get_contents("query.cache"));
>
> /*
> $querycache format:
>
> array('sql' => array(), 'result'=>array(), 'time'=>array());
>
> For each sql statement 'sql' you have a result array.
> */
> // run all your queries through a function:
> function query($sql) {
> $cached = array_search($sql, $querycache['sql'])
> // check to see if the result is old
> if (time() - $querycache['time'][$cached] > $max_time) {
> unset($querycache['time'][$cached]);
> unset($querycache['sql'][$cached]);
> unset($querycache['result'][$cached]);
> $cached = false;
> }
> if ($cached) {
> return $querycache['result'][$cached];
> } else {
> $result = mysql_query($sql);
> $querycache['sql'][] = $sql;
> $index = array_search($querycache['sql']);
> $querycache['time'][$index] = time();
> while ($r = assoc($result)) {
> $querycache['result'][$index][] = $r;
> }
> // save cache for other scripts
> file_put_contents('query.cache', serialize($querycache));
> return $querycache['result'][$index];
> }
> }
>
> ... It's actually kind of a complicated process now that I'm thinking
> about it.
>
> -Micah
>
>
>
>
>
> On 03/13/2007 06:20 AM, Vincent wrote:
> > Hi all,
> >
> > I'm trying to improve the performance for visitors, and I want to know
> > if there is some way to store the mySQL results of .php scripts in
> > webpages.
> >
> > So, in example, when requesting
> > http://www.mydomain.com/script.php?id=110 , it can be redirected to
> > his cached version http://www.mydomain.com/id110.html.
> >
> >
> > Any code or information would be appreciated,
> >
> >
> > Regards,
> >
> >
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

------=_Part_68898_32075225.1173942369652--

Re: Caching query results in html pages

am 15.03.2007 08:48:18 von dmagick

Amit Patel wrote:
> I believe a much better solution would be to use MySQL Query Cache.
> http://dev.mysql.com/doc/refman/5.0/en/query-cache.html
>
> Use it wisely and there is a lot of performance gain. Donot simply enable
> cache for all sql statements.

Maybe if you have complete control over the server you can do this.

If you're on a shared host, you have no hope - anyone else's queries can
knock yours out of the cache and you're back to square 1.

Depending on the queries (and whether they are indexed or not) it might
not even be worth worrying about attempting to cache - it all depends on
the application really (whether the queries are needed, how it handles
the results etc).

--
Postgresql & php tutorials
http://www.designmagick.com/

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php