Re: Hwo to set timeout for PHP persistent connections
От | Steve Crawford |
---|---|
Тема | Re: Hwo to set timeout for PHP persistent connections |
Дата | |
Msg-id | 20030303182746.D8D75103D0@polaris.pinpointresearch.com обсуждение исходный текст |
Ответ на | Hwo to set timeout for PHP persistent connections (Gabriele Bartolini <g.bartol@comune.prato.it>) |
Список | 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
В списке pgsql-general по дате отправления: