Question

According to PHP.net manual, pg_pconnect will create a persistent connection, or will return the existing one if it already exists with same connection string.

The problem I have is I want to know whether that call indeed creates a connection or actually returns the same, for example, for loading prepared statements in case it is the first connection.

Can it actually be possible?

UPDATE: With this question I am not referring to the current running PHP script. I want to know if the connection has been opened sometime (maybe by other scripts another time) or this script is the first in open that connection (for example, because I resetted the PostgreSQL server).

Était-ce utile?

La solution

Check the manual. Solution is given in its description itself. It returns the existing connection if you have enabled persistent connection, which is the enabled by default. I had no problem with it in my experience. Hope this helps out. php.net manual for pg_pconnect()

ANSWER UPDATED: i should add that normally postgres is very possesive towards its connections; it tries to retain the connections even if you reset the service; so it would be wise not use this event of "checking a pre-existing connection" as even if u found a mechanism to detect the new connection returned event, it will be countable by your fingers; very few very rare.

I think you should shift your logic.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top