Search Postgresql Archives

Re: persistent db connections in PHP

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello all!

I'm working on a PHP site using Postgres as a back-end. I have an
include at the top of each page that runs the pg_connect function.

I'm implementing some temporary tables, which I understand are
destroyed automatically at the end of the session. It seems to me that

	- Temp tables are local to a session (ie. a connection)
- Persistent connections in PHP creates a pool of connections. When you pg_pconnect() you get a connection from the pool. You have no control over which connection you get, so you don't really know if the temp tables have been created by a previous connection or not.

So, the best solution is to create the temp tables inside a transaction, with ON COMMIT DROP, do your work, and let them disappear. This will save you from getting temp tables already filled by stuff from the previous webpage which got this connection. For the same reason, pg_pconnect() should ALWAYS be followed by pg_query( "ROLLBACK" ). If you put rollback in register_shutdown_function(), be aware that it will NOT be called if your script is nuked for trying to malloc more than the allowed memory limit, or for other brutal reasons...

Also note that PHP, being PHP, sucks, and thusly, will not reconnect persistent connections when they fail. You have to kick it a bit.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux