Re: Hwo to set timeout for PHP persistent connections

From: Steve Crawford <scrawford(at)pinpointresearch(dot)com>
To: Gabriele Bartolini <g(dot)bartol(at)comune(dot)prato(dot)it>, PostgreSQL-General <pgsql-general(at)postgresql(dot)org>
Subject: Re: Hwo to set timeout for PHP persistent connections
Date: 2003-03-03 18:27:46
Message-ID: 20030303182746.D8D75103D0@polaris.pinpointresearch.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Short answer - check for the timeout settings in posgresql.conf.

Long answer: It's not a bug it's a feature.

PHP can be set to maintain persistent database connections. Persistent
connections can improve performance by eliminating the overhead of setting up
and tearing down the connection to the database on a use-by-use basis. This
can be good (doing a bunch of simple inserts on an open-do inserts-close vs.
doing an open-insert-close for each insert generally gives me a 10x boost in
performance) and is appropriate if 1) lots of your traffic requires database
access and 2) you have sufficient resources to maintain enough open
connections (typically one per web server process so look at your max
processes setting in your web server).

I'm not a PHP guru but I think there is a way to either explicitely close the
connection or to turn off persistence which may be better than having
PostgreSQL drop the connection. You could ask on the PHP list.

If you need performance then you really need to look into connection pooling
(like in aolserver or in Java app servers like jboss or check out one of the
postgresql pooling solutions). With a connection pool you can set up a "pool"
of persistent database connections that are shared by your various web server
threads. Whenever a process needs to access the database it gets an already
established connection from the pool and "returns" it when done. You only
need enough connections to satisfy you max need for simultaneous database
connections as the web process will not tie up a connection when not needed
(say when serving up an image file or sitting idle) and you get the speed
boost of having an established connection ready and waiting. Many pooling
systems will automatically increase and decrease the number of connections in
the pool as needed by the application.

Cheers,
Steve

On Monday 03 March 2003 8:27 am, Gabriele Bartolini wrote:
> Ciao guys,
>
> I need to set a reasonable low value of timeout for inactive
> connections, as they seem to stay up when a PHP script calls a
> pg_pconnect on the database server.
>
> As its main purpose is to serve a Web application, I'd love
> connections to get close after 10-15 seconds of inactivity.
>
> Is there a run-time configuration I can set in Postgres?
>
> Ciao and thanks
> -Gabriele

In response to

Browse pgsql-general by date

  From Date Subject
Next Message scott.marlowe 2003-03-03 18:30:42 Re: Hwo to set timeout for PHP persistent connections
Previous Message Stephan Szabo 2003-03-03 18:25:12 Re: almost there on a design