Jump to content


Photo

Children close parent's PG connection!


  • Please log in to reply
2 replies to this topic

#1 btherl

btherl
  • Staff Alumni
  • Advanced Member
  • 3,893 posts
  • LocationAustralia

Posted 21 March 2006 - 04:05 AM

I have a script which opens a connection with pg_connect(), and then forks off several children. When the children are finished, they exit.

Unfortunately, these children inherit the parent's postgres connection, and they close this connection when they exit.

Is there any way to stop the children from closing the connection?

#2 Jenk

Jenk
  • Members
  • PipPipPip
  • Advanced Member
  • 778 posts

Posted 15 September 2006 - 04:56 PM

Use a persistant connection:

http://www.php.net/m...pg-pconnect.php

But remember to use pg_close($linkid); else the connection will remain open until PG's own timeout clause is met.

#3 btherl

btherl
  • Staff Alumni
  • Advanced Member
  • 3,893 posts
  • LocationAustralia

Posted 18 September 2006 - 07:32 AM

Thanks for the suggestion!  I solved this by using pcntl_exec(), thus avoiding php's shutdown code.

pg_pconnect() doesn't work unfortunately, as the children believe they are the only running php process.  So they shut down all persistent connections on exit.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users