PHP Mysql query caching - how to stop it

PHP Mysql query caching - how to stop it

am 09.01.2008 17:49:58 von michalkuls

I have recently recognized a problem, described it in a post a few
hours ago, but have revised my opinion on the problem. Now it looks as
follows:
The portal runs on apache/php/mysql. Php generates a query, and the
result returned is from a cache, not from the actual mysql db. The
data I receive is not up-to-date - to changes I make during this
time.
I have tried using mysql_unbuffered_query, but doesn't help.
I have finally come to the solution. At the end of list of fields
following SELECT statement, I entered rand() function which causes
that every query is different from the previous...
Looks like this: SELECT field1,field2,...,rand() FROM ...

But this solution is ugly and very unproffesional.
Do you have any better idea?
How to stop php/apache from buffering/caching mysql query results?

Thanks for any hints
Michal

Re: PHP Mysql query caching - how to stop it

am 09.01.2008 20:28:34 von nc

On Jan 9, 8:49 am, michalk...@o2.pl wrote:
>
> The portal runs on apache/php/mysql. Php generates a query, and the
> result returned is from a cache, not from the actual mysql db. The
> data I receive is not up-to-date - to changes I make during this
> time.
> I have tried using mysql_unbuffered_query, but doesn't help.
> I have finally come to the solution. At the end of list of fields
> following SELECT statement, I entered rand() function which causes
> that every query is different from the previous...
> Looks like this: SELECT field1,field2,...,rand() FROM ...
>
> But this solution is ugly and very unproffesional.
> Do you have any better idea?
> How to stop php/apache from buffering/caching mysql query results?

Query caching is a MySQL-level setting; PHP and Apache have nothing to
do with it.

You have two options. One is to stop query caching entirely by
setting query_cache_type = 0 or query_cache_type = OFF in MySQL's
configuration file:

http://dev.mysql.com/doc/refman/4.1/en/server-system-variabl es.html#option_mysqld_query_cache_type

If you have no access to MySQL's configuration file, you can add a
SQL_NO_CACHE clause to your queries to request that MySQL run the
query rather than return a cached result:

SELECT SQL_NO_CACHE * FROM myTable;

See MySQL documentation:

http://dev.mysql.com/doc/refman/4.1/en/select.html

Cheers,
NC

Re: PHP Mysql query caching - how to stop it

am 10.01.2008 10:38:39 von michalkuls

On 9 Sty, 20:28, NC wrote:
> On Jan 9, 8:49 am, michalk...@o2.pl wrote:
>
>
>
> > The portal runs on apache/php/mysql. Php generates a query, and the
> > result returned is from a cache, not from the actual mysql db. The
> > data I receive is not up-to-date - to changes I make during this
> > time.
> > I have tried using mysql_unbuffered_query, but doesn't help.
> > I have finally come to the solution. At the end of list of fields
> > following SELECT statement, I entered rand() function which causes
> > that every query is different from the previous...
> > Looks like this: SELECT field1,field2,...,rand() FROM ...
>
> > But this solution is ugly and very unproffesional.
> > Do you have any better idea?
> > How to stop php/apache from buffering/caching mysql query results?
>
> Query caching is a MySQL-level setting; PHP and Apache have nothing to
> do with it.
>
> You have two options. =A0One is to stop query caching entirely by
> setting query_cache_type =3D 0 or query_cache_type =3D OFF in MySQL's
> configuration file:
>
> http://dev.mysql.com/doc/refman/4.1/en/server-system-variabl es.html#o...
>
> If you have no access to MySQL's configuration file, you can add a
> SQL_NO_CACHE clause to your queries to request that MySQL run the
> query rather than return a cached result:
>
> SELECT SQL_NO_CACHE * FROM myTable;
>
> See MySQL documentation:
>
> http://dev.mysql.com/doc/refman/4.1/en/select.html
>
> Cheers,
> NC

Thanks, this helps!
Michal