Обсуждение: Disconnect - required, recommended, or optional?

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

Disconnect - required, recommended, or optional?

От
"Rodolfo J. Paiz"
Дата:
Hi!

I've just noticed that there is a disconnect function in PEAR's DB
module. For web pages (written in PHP) that connect to PostgreSQL,
should I *always* disconnect when finished with that page's queries? Or
is it pretty much optional, or only used in high-traffic situations
where resource exhaustion is a concern?

My database gets less than 1 query per second, so I am not at all
concerned about resources. I am, however, concerned about acquiring good
programming habits as I go along.

Any advice welcome.

Cheers,

--
Rodolfo J. Paiz <rpaiz@simpaticus.com>


Re: Disconnect - required, recommended, or optional?

От
John DeSoi
Дата:
On Apr 4, 2005, at 12:40 PM, Rodolfo J. Paiz wrote:

> I've just noticed that there is a disconnect function in PEAR's DB
> module. For web pages (written in PHP) that connect to PostgreSQL,
> should I *always* disconnect when finished with that page's queries? Or
> is it pretty much optional, or only used in high-traffic situations
> where resource exhaustion is a concern?

I would say optional. The command is there if you need it (suppose you
have a long running script or open a lot of different connections), but
the connections are automatically released at the end of the script.
For scripts with a web page view type lifetime, I don't see the need to
worry about it. Here is what the php docs say about pg_close:

Note:  Using pg_close() is not usually necessary, as  non-persistent
open connections are automatically closed at the end  of the script.


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