On Fri, 2010-11-26 at 22:29 -0800, Tommy Pham wrote:

> > -----Original Message-----
> > From: Richard West [mailto:p...@cbnisp.com]
> > Sent: Friday, November 26, 2010 9:40 PM
> > To: Peter Lind
> > Cc: Tommy Pham; Tamara Temple; PHP General Mailing List
> > Subject: Re: [PHP] PHP Add +1 mysql updates by 2?
> > 
> > I took that into consideration so I added the update at the very end of
> > document...
> > Still the same,
> > RD
> > 
> <snip>
> Things to consider as part of your application design/flow:
> 1) Are you doing all PHP processing (application initialization, DB
> retrieval, user preference settings, etc.) before any header, echo, print,
> printf, output buffer, etc... ?  At which point is the update done?
> 2) Are you sure the DB update is only called for or included/required once
> for that particular URL request?
> 3) Do you any have other page (js - or in page ajax calls, css, php, html,
> etc) that requests the page (with the update) again, as Peter mentioned?
> It will help you if you do an UML or a flow chart of the application flow.
> Regards,
> Tommy

Because you're running the query as a response to a GET call, the
browser is allowed to call it multiple times and grab select parts of
the output to speed up rendering of the page. I've run into this before,
and it's annoying.

There are basically two ways to prevent this. Have the page called as
part of a POST request, which is preferred as GET requests should never
change data, hence why browsers are allowed to request them in a
slightly different way to speed up the page display times.

The second way is to also update a timestamp in the DB, and then before
you update check to see if it has been updated within a certain time
period. Depending on what you're updating this for (stat counter, etc)
then this may not work.


Reply via email to