2

I've changed pgsql.allow_persistent to Off in /etc/php.ini, and restarted apache.

Now I'm getting identical pg handles for two consecutive pg_connect.

Array
(
[0] => Resource id #14
[1] => Resource id #14
)

My question is, is php still using persistent connections, and what should be done if answer is yes.

mpapec
  • 50,217
  • 8
  • 67
  • 127
  • Two consecutive connections *within the same script run* though, right? If you run the same script repeatedly, does each run return different connections? Does `SELECT pg_backend_pid()` return the same value? – Craig Ringer Apr 07 '14 at 02:45
  • @CraigRinger yes, this is within the same script run. If I run script repeatedly `pg_backend_pid` changes, but it stays same within same run. – mpapec Apr 07 '14 at 09:36
  • Sounds likely that PHP still caches connections *within* a given script run, then. Do you get a different result if you use different connection options? – Craig Ringer Apr 07 '14 at 12:11
  • @CraigRinger tnx for the hint, when connecting with `PGSQL_CONNECT_FORCE_NEW` it has unique connections to the database within the same run. – mpapec Apr 07 '14 at 14:31

1 Answers1

1

PHP caches connections within any given script run, so multiple connect calls with the same params will return the same connection.

Unlike persistent connections this caching only occurs within a single script run.

As you found, you can disable this caching with the force new flag - PGSQL_CONNECT_FORCE_NEW.

Craig Ringer
  • 307,061
  • 76
  • 688
  • 778