Re: How to Cancel SQL Queries when Browser stops loading page?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

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


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux