Re: How to Cancel SQL Queries when Browser stops loading page?
| From: | Alexandre Florio | Date: | Wed, 21 May 2003 01:37:15 +0000 |
| Subject: | Re: How to Cancel SQL Queries when Browser stops loading page? | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-27937@lists.php.net to get a copy of this message | ||
Em Tue, 20 May 2003 21:19:03 GMT
Peter Miller <peteskitoo@aol.com> escreveu:
> We sometimes experience slow ups because users who run queries via a
> browser are retrying or stopping the query (by hitting the reload or
> stop buttons on the browser) before the queries complete.
I don't think that stopping the browser would increase the query time, but
if the user reloads the page repeatedly, you can save DB server time by
doing something like that:
$query = "SELECT * FROM foo";
if (!$_SESSION['is_executing_query']) {
$_SESSION['is_executing_query'] = true;
$rs = mysql_query($query);
$_SESSION['is_executing_query'] = false;
} else // is executing query
exit;
Note that reloading the browser should not be a problem unless your query
is _very_ CPU intensive, or your DB server is really busy (so that the
query execution time is greater then the
browser-request->httpd->browser->reload-request cycle which, normally, is
much greater then the query execution time).
Note also that using the code above, if the user reloads the browser while
the query is executing, he won't get any output (you can solve this by
placing the query result in the session and doing some more logic).
hth,
--af