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.