> 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.