2

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

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

I should have clarified a bit my question, I am sorry for missunderstanding. I will update my question accordingly.
Yes, I have read that. Thank you, this was just an idea, not implemented yet, but yes. It seems I need to load the prepared sentence anytime I open the connection (despite it may be already opened) and just ignore if it fails because it is already loaded?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.