pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Muhyiddin A.M Hayat <middink@indo.net.id>
To: Noel <noel.faux@med.monash.edu.au>
To: pgsql-php@postgresql.org
Subject: Re: Cancel a query when user leaves a web page
Date: Thu, 20 Nov 2003 01:44:08 +0800
Message-ID: <00aa01c3aec5$3fb5df60$2b179fca@middinkcomp> (raw)
References: <3FB984FA.1090003@med.monash.edu.au>

<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>

  ----- Original Message ----- 
  From: Noel 
  To: pgsql-php@postgresql.org 
  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 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

view thread (4+ messages)  latest in thread

Message-ID: <00aa01c3aec5$3fb5df60$2b179fca@middinkcomp>
Permalink:  ../00aa01c3aec5$3fb5df60$2b179fca@middinkcomp/
Also on:    postgresql.org/message-id/00aa01c3aec5$3fb5df60$2b179fca@middinkcomp

 · 

reply

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: middink@indo.net.id, noel.faux@med.monash.edu.au
  Subject: Re: Cancel a query when user leaves a web page
  In-Reply-To: <00aa01c3aec5$3fb5df60$2b179fca@middinkcomp>
  References: <3FB984FA.1090003@med.monash.edu.au> <00aa01c3aec5$3fb5df60$2b179fca@middinkcomp>

* 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