Re: Cancel a query when user leaves a web page

Поиск
Список
Период
Сортировка
От ljb
Тема Re: Cancel a query when user leaves a web page
Дата
Msg-id bpej5f$54o$1@news.hub.org
обсуждение исходный текст
Ответ на Cancel a query when user leaves a web page  (Noel <noel.faux@med.monash.edu.au>)
Список pgsql-php
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.

В списке pgsql-php по дате отправления:

Предыдущее
От: Noel
Дата:
Сообщение: Cancel a query when user leaves a web page
Следующее
От: "Muhyiddin A.M Hayat"
Дата:
Сообщение: Re: Cancel a query when user leaves a web page