Skip site navigation (1) Skip section navigation (2)

Re: Cancel a query when user leaves a web page

From: ljb <ljb220(at)mindspring(dot)com>
To: pgsql-php(at)postgresql(dot)org
Subject: Re: Cancel a query when user leaves a web page
Date: 2003-11-19 02:05:35
Message-ID: bpej5f$54o$1@news.hub.org (view raw or flat)
Thread:
Lists: pgsql-php
noel(dot)faux(at)med(dot)monash(dot)edu(dot)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.

In response to

pgsql-php by date

Next:From: Muhyiddin A.M HayatDate: 2003-11-19 17:44:08
Subject: Re: Cancel a query when user leaves a web page
Previous:From: NoelDate: 2003-11-18 02:33:30
Subject: Cancel a query when user leaves a web page

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group