From noel.faux@med.monash.edu.au Tue Nov 18 02:52:32 2003 X-Original-To: pgsql-php-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id C1BD5D1CA65 for ; Tue, 18 Nov 2003 02:52:32 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 16596-02 for ; Mon, 17 Nov 2003 22:52:04 -0400 (AST) Received: from ALPHA9.ITS.MONASH.EDU.AU (alpha9.its.monash.edu.au [130.194.1.9]) by svr1.postgresql.org (Postfix) with ESMTP id 9EE23D1CAD0 for ; Mon, 17 Nov 2003 22:49:19 -0400 (AST) Received: from localhost ([130.194.13.84]) by vaxh.its.monash.edu.au (PMDF V5.2-31 #39306) with ESMTP id <01L36G6XAYB28ZRW5V@vaxh.its.monash.edu.au> for pgsql-php@postgresql.org; Tue, 18 Nov 2003 13:31:48 +1100 Received: from blammo.its.monash.edu.au (localhost.its.monash.edu.au [127.0.0.1]) by localhost (Postfix) with ESMTP id 6250F39C003 for ; Tue, 18 Nov 2003 13:31:48 +1100 (EST) Received: from med.monash.edu.au (cl-13B-103-akira-whisstock.med.monash.edu.au [130.194.193.147]) by blammo.its.monash.edu.au (Postfix) with ESMTP id 43B592DC003 for ; Tue, 18 Nov 2003 13:31:48 +1100 (EST) Date: Tue, 18 Nov 2003 13:33:30 +1100 From: Noel Subject: Cancel a query when user leaves a web page To: pgsql-php@postgresql.org Message-id: <3FB984FA.1090003@med.monash.edu.au> MIME-version: 1.0 Content-type: MULTIPART/ALTERNATIVE; BOUNDARY="Boundary_(ID_HmeUQXJ/q/MVS8FcWBpQCw)" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax) X-Accept-Language: en-us, en X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200311/41 X-Sequence-Number: 2434 This is a multi-part message in MIME format. --Boundary_(ID_HmeUQXJ/q/MVS8FcWBpQCw) Content-type: text/plain; format=flowed; charset=us-ascii Content-transfer-encoding: 7BIT Hi all, 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. I've been thinking about mixing php and javascript. Is this the best way to go about it? basic out line of my code: ....stuff.... ...stuff The query can take some time. And when the page is left the query is still running on postmaster. Have tried )> The function, close_connection($connection), is defined in the include file, which is the connection is busy, cancels the query and closes the connection. This gives the following error: Resource id #1 Warning: pg_send_query(): 1 is not a valid PostgreSQL link resource in /home/fauxn/public_html/singleAArepeats/test.php on line 11 Any suggestions welcome. Many thanks -- Noel Faux Department of Biochemistry and Molecular Biology Monash University Clayton 3168 Victoria Australia --Boundary_(ID_HmeUQXJ/q/MVS8FcWBpQCw) Content-type: text/html; charset=us-ascii Content-transfer-encoding: 7BIT Hi all,

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.

I've been thinking about mixing php and javascript. Is this the best way to go about it?

basic out line of my code:
<html><head>....stuff....</head>
<body>...stuff
<?php
    $connection = pg_connect(host, dbname, user);

    pg_send_query($connection, "SELECT * FROM blah");

    // collect the results and display etc..
?>
</body></html>
The query can take some time.
And when the page is left the query is still running on postmaster.

Have tried
<?php
    include "functions.php";
    $connection = pg_connect(host, dbname, user);
?>
<html><body onunload(<?close_connection($connection)?>)>
<?php
    echo $connection;
    pg_send_query($connection, "SELECT * FROM blah");

    // collect the results and display etc..
?>
</body></html>

The function, close_connection($connection), is defined in the include file, which is the connection is busy, cancels the query and closes the connection.

This gives the following error:

Resource id #1
Warning: pg_send_query(): 1 is not a valid PostgreSQL link resource in /home/fauxn/public_html/singleAArepeats/test.php on line 11

Any suggestions welcome.

Many thanks
-- 
Noel Faux
Department of Biochemistry and Molecular Biology
Monash University
Clayton 3168
Victoria
Australia
--Boundary_(ID_HmeUQXJ/q/MVS8FcWBpQCw)-- From ljb220@mindspring.com Wed Nov 19 02:20:24 2003 X-Original-To: pgsql-php-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id DCAA4D1B50A for ; Wed, 19 Nov 2003 02:20:24 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 62618-09 for ; Tue, 18 Nov 2003 22:19:56 -0400 (AST) Received: from news.hub.org (news.hub.org [200.46.204.72]) by svr1.postgresql.org (Postfix) with ESMTP id 29329D1D7BC for ; Tue, 18 Nov 2003 22:19:53 -0400 (AST) Received: from news.hub.org (news.hub.org [200.46.204.72]) by news.hub.org (8.12.9/8.12.9) with ESMTP id hAJ2JqNu056713 for ; Wed, 19 Nov 2003 02:19:52 GMT (envelope-from news@news.hub.org) Received: (from news@localhost) by news.hub.org (8.12.9/8.12.9/Submit) id hAJ25a7P012281 for pgsql-php@postgresql.org; Wed, 19 Nov 2003 02:05:36 GMT From: ljb X-Newsgroups: comp.databases.postgresql.interfaces.php Subject: Re: Cancel a query when user leaves a web page Date: Wed, 19 Nov 2003 02:05:35 +0000 (UTC) Organization: Hub.Org Networking Services Lines: 21 Message-ID: References: <3FB984FA.1090003@med.monash.edu.au> X-Complaints-To: usenet@news.hub.org User-Agent: slrn/0.9.8.0 (Linux) To: pgsql-php@postgresql.org X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200311/42 X-Sequence-Number: 2435 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 > include "functions.php"; > $connection = pg_connect(host, dbname, user); > ?> > )> ... 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. From middink@indo.net.id Wed Nov 19 17:36:17 2003 X-Original-To: pgsql-php-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 483B2D1CA82 for ; Wed, 19 Nov 2003 17:36:17 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 25917-03 for ; Wed, 19 Nov 2003 13:35:45 -0400 (AST) Received: from smtp-1.indo.net.id (smtp-1.indo.net.id [202.159.32.91]) by svr1.postgresql.org (Postfix) with SMTP id 96BB0D1CCDF for ; Wed, 19 Nov 2003 13:34:53 -0400 (AST) Received: (qmail 11967 invoked from network); 20 Nov 2003 00:34:48 +0700 Received: from smtp.indo.net.id (202.159.32.81) by smtp-1.indo.net.id with SMTP; 20 Nov 2003 00:34:48 +0700 Received: (qmail 19343 invoked from network); 19 Nov 2003 17:32:02 -0000 Received: from unknown (HELO smtp.surabaya.indo.net.id) (202.159.51.117) by smtp.indo.net.id with SMTP; 19 Nov 2003 17:32:02 -0000 Received: from smtp [202.159.51.117] by smtp.surabaya.indo.net.id (SMTPD32-7.10) id AC6B3251003E; Thu, 20 Nov 2003 00:46:19 +0700 Received: FROM middinkcomp BY smtp ; Thu Nov 20 00:46:16 2003 +0700 Message-ID: <00aa01c3aec5$3fb5df60$2b179fca@middinkcomp> From: "Muhyiddin A.M Hayat" To: "Noel" , References: <3FB984FA.1090003@med.monash.edu.au> Subject: Re: Cancel a query when user leaves a web page Date: Thu, 20 Nov 2003 01:44:08 +0800 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_009D_01C3AF07.CA3727B0" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 X-Virus-Scanned: by amavisd-new at postgresql.org X-Spam-Status: No, hits=1.5 tagged_above=0.0 required=5.0 tests=HTML_60_70, HTML_EVENT_UNSAFE, HTML_FONT_COLOR_BLUE, HTML_FONT_COLOR_GRAY, HTML_FONT_COLOR_RED, HTML_FONT_COLOR_UNSAFE, HTML_JAVASCRIPT, REFERENCES, SMTPD_IN_RCVD X-Spam-Level: * X-Archive-Number: 200311/43 X-Sequence-Number: 2436 This is a multi-part message in MIME format. ------=_NextPart_000_009D_01C3AF07.CA3727B0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable )> onunload above can't call function from PHP, but it called from javascript,= you can create javascript function to call PHP function/file that you wann= a PHP do=20 window.close();"; ?> --------- ----- Original Message -----=20 From: Noel=20 To: pgsql-php@postgresql.org=20 Sent: Tuesday, November 18, 2003 10:33 AM Subject: [PHP] Cancel a query when user leaves a web page Hi all, I have a small problem. Is it possible to cancel a running query when a p= erson leave or pressed the stop button in my web page. I've been thinking about mixing php and javascript. Is this the best way = to go about it? basic out line of my code: ....stuff.... ...stuff The query can take some time. And when the page is left the query is still running on postmaster. Have tried )> The function, close_connection($connection), is defined in the include fi= le, which is the connection is busy, cancels the query and closes the conne= ction. This gives the following error: Resource id #1 Warning: pg_send_query(): 1 is not a valid PostgreSQL link resource in /h= ome/fauxn/public_html/singleAArepeats/test.php on line 11 Any suggestions welcome. Many thanks --=20 Noel Faux Department of Biochemistry and Molecular Biology Monash University Clayton 3168 Victoria Australia ------=_NextPart_000_009D_01C3AF07.CA3727B0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable

<body=20 onunload(<?close_connection($connection)?>)>

onunload above can't call fu= nction from=20 PHP, but it called from javascript, you can create javascript fun= ction=20 to call PHP function/file that you wanna PHP do 

<?php
// close_connection.php
include(
'connection.php');
global
$connection;

function close_connection(
$connection){
//=20 close_connection here
= //=20 .....
// .....
// .....

}

close_connection(
$connection);
echo
"<SCRIPT>window.close();</SCRIPT>";
?>

---------

<html>

<= ;SCRIPT LANGUAGE=3D"JavaScript">
=
<!-- Begin
function leave()= {
window.open('close_connection.php','','toolbar=3Dno,menubar=3Dno,l= ocation=3Dno,height=3D10,width=3D10');
}
// End -->
</SCRIPT>

<body=20 onunload<= FONT=20 face=3D"Courier New" color=3D#008080 size=3D1> =3D=20 "leave()">

</
body>
</html>

----- Original Message -----
Fro= m:=20 Noel
To: pgsql-php@postgresql.org
Sent: Tuesday, November 18, 2003 1= 0:33=20 AM
Subject: [PHP] Cancel a query when= user=20 leaves a web page

Hi all,

I have a small problem. Is it possible to c= ancel=20 a running query when a person leave or pressed the stop button in my web= =20 page.

I've been thinking about mixing php and javascript. Is this = the=20 best way to go about it?

basic out line of my=20 code:
<html><head>....stuff....</head>
<body&g= t;...stuff
<?php
   =20 $connection =3D pg_connect(host, dbname, user);

   = =20 pg_send_query($connection, "SELECT * FROM blah");

  &nbs= p; //=20 collect the results and display=20 etc..
?>
</body></html>
The query can take some= =20 time.
And when the page is left the query is still running on=20 postmaster.

Have tried
<?php
    include= =20 "functions.php";
    $connection =3D pg_connect(host, d= bname,=20 user);
?>
<html><body=20 onunload(<?close_connection($connection)?>)>
<?php
&nbs= p;  =20 echo $connection;
    pg_send_query($connection, "SELEC= T *=20 FROM blah");

    // collect the results and display= =20 etc..
?>
</body></html>

The function,=20 close_connection($connection), is defined in the include file, which is t= he=20 connection is busy, cancels the query and closes the connection.

T= his=20 gives the following error:

Resource id #1
Warning:=20 pg_send_query(): 1 is not a valid PostgreSQL link resource in=20 /home/fauxn/public_html/singleAArepeats/test.php on line=20 11

Any suggestions welcome.

Many thanks
--=20 Noel Faux Department of Biochemistry and Molecular Biology Monash University Clayton 3168 Victoria Australia
------=_NextPart_000_009D_01C3AF07.CA3727B0-- From noel.faux@med.monash.edu.au Tue Dec 16 08:38:11 2003 X-Original-To: pgsql-php-postgresql.org@localhost.postgresql.org Received: from localhost (neptune.hub.org [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 08C22D1B4E1 for ; Tue, 16 Dec 2003 08:38:11 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 98256-04 for ; Tue, 16 Dec 2003 04:37:41 -0400 (AST) Received: from ALPHA9.ITS.MONASH.EDU.AU (alpha9.its.monash.edu.au [130.194.1.9]) by svr1.postgresql.org (Postfix) with ESMTP id 7B71DD1B464 for ; Tue, 16 Dec 2003 04:37:37 -0400 (AST) Received: from localhost ([130.194.13.85]) by vaxh.its.monash.edu.au (PMDF V5.2-31 #39306) with ESMTP id <01L49VNM5NSQ8ZW6CC@vaxh.its.monash.edu.au> for pgsql-php@postgresql.org; Tue, 16 Dec 2003 18:56:03 +1100 Received: from broink.its.monash.edu.au (localhost.its.monash.edu.au [127.0.0.1]) by localhost (Postfix) with ESMTP id 0DE62158002; Tue, 16 Dec 2003 18:56:02 +1100 (EST) Received: from med.monash.edu.au (cl-13B-103-akira-whisstock.med.monash.edu.au [130.194.193.147]) by broink.its.monash.edu.au (Postfix) with ESMTP id E04CD120004; Tue, 16 Dec 2003 18:56:01 +1100 (EST) Date: Tue, 16 Dec 2003 18:58:17 +1100 From: Noel Subject: Re: Cancel a query when user leaves a web page In-reply-to: <00aa01c3aec5$3fb5df60$2b179fca@middinkcomp> To: "Muhyiddin A.M Hayat" , pgsql-php@postgresql.org, ljb220@mindspring.com, Di Wu Message-id: <3FDEBB19.9050100@med.monash.edu.au> MIME-version: 1.0 Content-type: MULTIPART/ALTERNATIVE; BOUNDARY="Boundary_(ID_guCDxg5vhcnlCQv3p5oAOw)" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax) X-Accept-Language: en-us, en References: <3FB984FA.1090003@med.monash.edu.au> <00aa01c3aec5$3fb5df60$2b179fca@middinkcomp> X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200312/41 X-Sequence-Number: 2487 This is a multi-part message in MIME format. --Boundary_(ID_guCDxg5vhcnlCQv3p5oAOw) Content-type: text/plain; format=flowed; charset=us-ascii Content-transfer-encoding: 7BIT Hi all, Sorry for the delayed response, I've added both Hayat's and ljb220's suggestions. I've tried both, but still having problems. Code: //---------------------- test.php "; echo pg_connection_status($connection)." status
"; pg_send_query($connection, "SELECT COUNT(id) FROM test"); // expected to take ~2min enough time to press stop echo pg_connection_busy($connection)." busy
"; $res = pg_get_result($connection); echo pg_num_rows($res)." # rows
"; echo $GLOBALS["connection"]." GLOBALS
"; ?> //-------------------------------------- close.php "; $f = fopen("/home/xxx/log","w"); // log file to trace the code etc... fwrite($f,"new page\n"); fclose($f); close_con(); echo "closed"; echo ""; ?> //-------------------------------- functions.php With this set up, the user enters test.php. Stops before the query finishes. It should call leave(). However, this dose not happen. I believe it is because the script has not finished and passed the page text to the browser (pls correct me if I'm wrong), until php has finished processing it. I've tried using register_shutdown_function() as: test.php "; echo pg_connection_status($connection)." status
"; pg_send_query($connection, "SELECT COUNT(id) FROM test"); echo pg_connection_busy($connection)." busy
"; $res = pg_get_result($connection); echo pg_num_rows($res)." # rows
"; echo $GLOBALS["connection"]." GLOBALS
"; ?> The functions.php as above. This also dose not work as, " The registered shutdown functions are called after the request has been completed" (from http://au2.php.net/manual/en/function.register-shutdown-function.php ). I'm interpreting that as, any functions in the list will not be called until the pg_send_query() or the pg_get_result(), not sure which, returns. Then close_con() from functions.php is called via register_shutdown_function(). Thus I'm unable to cancel the query :( Any comments, suggestions or work arounds would be greatly appreciated. I'm using PHP 4.2.3 Cheers Noel //----------------------------------------------------------------------------- Muhyiddin A.M Hayat wrote: > )> > > onunload above can't call function from PHP, but it called from > javascript, you can create javascript function to call PHP > function/file that you wanna PHP do > > // close_connection.php > include('connection.php'); > global $connection; > > function close_connection($connection){ > // close_connection here > // ..... > // ..... > // ..... > > } > > close_connection($connection); > echo ""; > ?> > > --------- > > > > > > > > > > //---------------------------------------- ljb wrote: 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 > include "functions.php"; > $connection = pg_connect(host, dbname, user); >?> >)> > > > ... > > 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. -- Noel Faux Department of Biochemistry and Molecular Biology Monash University Clayton 3168 Victoria Australia --Boundary_(ID_guCDxg5vhcnlCQv3p5oAOw) Content-type: text/html; charset=us-ascii Content-transfer-encoding: 7BIT Hi all,
Sorry for the delayed response, I've added both Hayat's and ljb220's suggestions.

I've tried both, but still having problems.
Code:
//----------------------
test.php
<html>
<script language="JavaScript">
<!-- Begin
function leave() {
    window.open('close.php','','toolbar=no,menubar=no,location=no,height=10,width=10','');
}
// end -->
</script>
<body onunload = 'leave()'>
<?php include "functions.php";
    global $connection;
    $connection = pg_connect("host=localhost dbname=test user=test");
    echo $connection." connection <br>";
    echo pg_connection_status($connection)." status<br>";
    pg_send_query($connection, "SELECT COUNT(id) FROM test"); // expected to take ~2min enough time to press stop
    echo pg_connection_busy($connection)." busy<br>";
    $res = pg_get_result($connection);
    echo pg_num_rows($res)." # rows<br>";
    echo $GLOBALS["connection"]." GLOBALS<br>";
?>
</body></html>

//--------------------------------------
close.php
<?php include "functions.php";
    echo "closing connection<br>";
    $f = fopen("/home/xxx/log","w"); // log file to trace the code etc...
    fwrite($f,"new page\n");
    fclose($f);
    close_con();
    echo "closed";
    echo "<script>window.close();</script>";
?>

//--------------------------------
functions.php
<?php
/* when the page is exited, if the connection is not null, cancel and sql statements and
      close the database connection */
    function close_con() {
        $f = fopen("/home/xxx/log","w"); // log file to trace the code etc...
        $connection = $GLOBALS["connection"];
        fwrite($f,"Closing connection\n");
        $status = pg_connection_status($connection);
        fwrite($f, $status." status\n");
        if($status == 0){// connected
            fwrite($f, "connected\n");
            if(pg_connection_busy($connection)) {// busy so cancel last query
                fwrite($f, "connection busy\n");
                pg_cancel_query($connection);
                fwrite($f, "query killed\n");
            }
            // close connection
            pg_close($connection);
            fwrite($f, "connection closed");
        }
        else {
            fwrite($f, "not connected\n");
        }
        fclose($f);
    }
?>

With this set up, the user enters test.php. Stops before the query finishes. It should call leave(). However, this dose not happen. I believe it is because the script has not finished and passed the page text to the browser (pls correct me if I'm wrong), until php has finished processing it.

I've tried using register_shutdown_function() as:
test.php
<html>
<body>
<?php include "functions.php";
    global $connection;
    $connection = pg_connect("host=localhost dbname=test user=test");
    register_shutdown_function("close_con");
    echo $connection." connection <br>";
    echo pg_connection_status($connection)." status<br>";
    pg_send_query($connection, "SELECT COUNT(id) FROM test");
    echo pg_connection_busy($connection)." busy<br>";
    $res = pg_get_result($connection);
    echo pg_num_rows($res)." # rows<br>";
    echo $GLOBALS["connection"]." GLOBALS<br>";
?>
</body></html>

The functions.php as above.

This also dose not work as, " The registered shutdown functions are called after the request has been completed" (from http://au2.php.net/manual/en/function.register-shutdown-function.php ). I'm interpreting that as, any functions in the list will not be
called until the pg_send_query() or the pg_get_result(), not sure which, returns. Then close_con() from functions.php is called via register_shutdown_function(). Thus I'm unable to cancel the query :(

Any comments, suggestions or work arounds would be greatly appreciated.

I'm using PHP 4.2.3

Cheers
Noel

//-----------------------------------------------------------------------------
Muhyiddin A.M Hayat wrote:

<body onunload(<?close_connection($connection)?>)>

onunload above can't call function from PHP, but it called from javascript, you can create javascript function to call PHP function/file that you wanna PHP do 

<?php
// close_connection.php
include(
'connection.php');
global
$connection;

function close_connection(
$connection){
// close_connection here
// .....
// .....
// .....

}

close_connection(
$connection);
echo
"<SCRIPT>window.close();</SCRIPT>";
?>

---------

<html>

<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function leave() {
window.open('close_connection.php','','toolbar=no,menubar=no,location=no,height=10,width=10');
}
// End -->
</SCRIPT>

<body onunload = "leave()">

</body>
</html>

//----------------------------------------
ljb wrote:
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.


-- 
Noel Faux
Department of Biochemistry and Molecular Biology
Monash University
Clayton 3168
Victoria
Australia
--Boundary_(ID_guCDxg5vhcnlCQv3p5oAOw)--