Обсуждение: Trouble with conections between php and postgre

Поиск
Список
Период
Сортировка

Trouble with conections between php and postgre

От
luis linietsky
Дата:
Hi !, first of all: sorry about my english, i'm not from us.
I 'm using latest versions of postgre 7.4 with php4 and apache2, on a
debian system. I'm working with a really big database, so there are
many querys that takes too much time to be executed (And there's
nothig to do about it). These querys blocks the php page while's being
loaded. The problem is that usually, one excepcts to stop those querys
or even close the conection if the user stops the explorer or closes
the window. However, this isn't hapening, the query keeps running in
the database, using resources.
I already try uselessly ignore_user_abort(False), and I don't want to
set a time limit.
¿Any ideas? ¿Am I missing something ?
Thnxs !
(Please, try avoiding those messages like "Get more resources",
"Optimize your querys", "/etc/init.d/postgresql restart", etc.)

Re: Trouble with conections between php and postgre

От
John DeSoi
Дата:
On Oct 3, 2005, at 9:59 AM, luis linietsky wrote:

> Hi !, first of all: sorry about my english, i'm not from us.
> I 'm using latest versions of postgre 7.4 with php4 and apache2, on a
> debian system. I'm working with a really big database, so there are
> many querys that takes too much time to be executed (And there's
> nothig to do about it). These querys blocks the php page while's being
> loaded. The problem is that usually, one excepcts to stop those querys
> or even close the conection if the user stops the explorer or closes
> the window. However, this isn't hapening, the query keeps running in
> the database, using resources.
> I already try uselessly ignore_user_abort(False), and I don't want to
> set a time limit.
> ¿Any ideas? ¿Am I missing something ?

There is a specific protocol for canceling a query in progress. Maybe
this PHP function will work for you:

http://www.php.net/manual/en/function.pg-cancel-query.php




John DeSoi, Ph.D.
http://pgedit.com/
Power Tools for PostgreSQL


Re: Trouble with conections between php and postgre

От
"Daniel Walters"
Дата:
The lock is caused by PHP the page running the queries locking the user's
SESSION file. The php script execution suspends when running each query so
the lock remains. Subsequent page requests will all pause at
session_start(); while waiting for the lock to be removed.

A session_write_close(); (call it before any db_query is run) can be of
assistance because it writes out the session file and thus no lock will be
kept. The problem is that this will send a cookie header to the client.
Multiple calls send further cookie headers :( IE will die with an unhelpful
error page if it receives around 25 of these headers...

What they really need to implement is a session_pause() and
session_restart(). This has been suggested before and there was even
documentation for these functions but it never made it into a PHP as far I
was aware and the documentation has since been removed from more recent PHP
documentation.

A more permanent way around this might be to use a database to hold the
sessions so you are not subject to the file-locking limitations.
Alternatively you could overide the file based session handling with your
own implementation and choose to discard session data from pages if a more
recent page has tried to access the session.

Regards,

Daniel Walters

-----Original Message-----
From: pgsql-php-owner@postgresql.org [mailto:pgsql-php-owner@postgresql.org]
On Behalf Of luis linietsky
Sent: Tuesday, October 04, 2005 12:00 AM
To: pgsql-php@postgresql.org
Subject: [PHP] Trouble with conections between php and postgre

Hi !, first of all: sorry about my english, i'm not from us.
I 'm using latest versions of postgre 7.4 with php4 and apache2, on a debian
system. I'm working with a really big database, so there are many querys
that takes too much time to be executed (And there's nothig to do about it).
These querys blocks the php page while's being loaded. The problem is that
usually, one excepcts to stop those querys or even close the conection if
the user stops the explorer or closes the window. However, this isn't
hapening, the query keeps running in the database, using resources.
I already try uselessly ignore_user_abort(False), and I don't want to set a
time limit.
¿Any ideas? ¿Am I missing something ?
Thnxs !
(Please, try avoiding those messages like "Get more resources", "Optimize
your querys", "/etc/init.d/postgresql restart", etc.)

---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings


Re: Trouble with conections between php and postgre

От
"Daniel Walters"
Дата:
Hi John,

I have some clarification on your suggestion...

This function is specifically for asynchronous queries though - if  Luis is
not using asynchronous queries the mileage may vary. The other issue is that
even if the query can be cancelled how does Luis accurately determine when
to do this?

To detect a closed or stopped/cancelled browser (see the notes in the php
manual under connection_status();) the script actually needs to poll the
client (this can be done by flushing a single character in a loop down to
the browser - this is ugly for a lot of fairly obvious reasons).

I think the key to issue is the session locking (as per my previous post).

There is quite a history to this issue (browsing the archives of this list
and Usenet reveals this) and it is in fact the reason why I am on this list.

The issue has also been raised as bugs at http://bugs.php.net but have been
systematically closed without fixes since as early as 2001.

Requests have been made for the addition of functions to pause a session
(remove the file lock while a query is running because you know the session
wont be written to during this time) and then restart the session (once the
query has completed).

This type of functionality can be somewhat achieved with
session_write_close() except that this function unfortunately sends a cookie
header automatically and this causes issues for IE if done repeatedly.

I have made some suggestions in my previous post (which is being moderated
currently) which may help but they are certainly not clean solutions.
Hopefully someone will take notice (this time) of this thread and work on
making php deal with this better.

Regards,

Daniel Walters.

-----Original Message-----
From: pgsql-php-owner@postgresql.org [mailto:pgsql-php-owner@postgresql.org]
On Behalf Of John DeSoi
Sent: Tuesday, October 04, 2005 11:17 AM
To: luis linietsky
Cc: pgsql-php@postgresql.org
Subject: Re: [PHP] Trouble with conections between php and postgre


On Oct 3, 2005, at 9:59 AM, luis linietsky wrote:

> Hi !, first of all: sorry about my english, i'm not from us.
> I 'm using latest versions of postgre 7.4 with php4 and apache2, on a
> debian system. I'm working with a really big database, so there are
> many querys that takes too much time to be executed (And there's
> nothig to do about it). These querys blocks the php page while's being
> loaded. The problem is that usually, one excepcts to stop those querys
> or even close the conection if the user stops the explorer or closes
> the window. However, this isn't hapening, the query keeps running in
> the database, using resources.
> I already try uselessly ignore_user_abort(False), and I don't want to
> set a time limit.
> ¿Any ideas? ¿Am I missing something ?

There is a specific protocol for canceling a query in progress. Maybe this
PHP function will work for you:

http://www.php.net/manual/en/function.pg-cancel-query.php




John DeSoi, Ph.D.
http://pgedit.com/
Power Tools for PostgreSQL


---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

               http://www.postgresql.org/docs/faq