From: ljb <ljb220@mindspring.com>
To: pgsql-php@postgresql.org
Subject: Re: Cancel a query when user leaves a web page
Date: Wed, 19 Nov 2003 02:05:35 +0000 (UTC)
Message-ID: <bpej5f$54o$1@news.hub.org> (raw)
References: <3FB984FA.1090003@med.monash.edu.au>
noel.faux@med.monash.edu.au wrote:
> I have a small problem. Is it possible to cancel a running query when a
> person leave or pressed the stop button in my web page.
> ...
> Have tried
> <?php
> include "functions.php";
> $connection = pg_connect(host, dbname, user);
> ?>
> <html><body onunload(<?close_connection($connection)?>)>
...
This will never work, as you found. The Javascript action is client-side
and PHP is server-side.
Try using register_shutdown_function() to register a function which will
call pg_cancel_query(). As long as PHP isn't ignoring user aborts (see
ignore_user_abort()), your query will be cancelled when the user hits STOP.
Another way is to ignore user aborts, and while waiting for the
asynchronous query to finish, keep calling connection_aborted() to see if
you are still connected to the user; if not you cancel the query and exit.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-php@postgresql.org
Cc: ljb220@mindspring.com
Subject: Re: Cancel a query when user leaves a web page
In-Reply-To: <bpej5f$54o$1@news.hub.org>
References: <3FB984FA.1090003@med.monash.edu.au> <bpej5f$54o$1@news.hub.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox