Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pg_pconnect safe? #190

Open
klaussilveira opened this issue May 28, 2024 · 1 comment
Open

pg_pconnect safe? #190

klaussilveira opened this issue May 28, 2024 · 1 comment

Comments

@klaussilveira
Copy link

Since the README documents that globals are unsafe, and so are singletons, I was wondering if pg_pconnect is also considered unsafe for ngx-php code. Is a connection pooler like pgbouncer a preferred alternative?

@joanhey
Copy link
Contributor

joanhey commented Jun 2, 2024

It's safe to use pg_pconnect(), but it's more useful in a shared nothing mode, like PHP-FPM.

Ngx-php boots your application once, keeps it in memory, and then feeds it requests. So if you don't close a normal pg_connect(), it'll be open and don't need a "p" connect(). Only be careful that all databases have a timeout for connections, so you need to send a simple "select 1" to maintain it open or use a reconnect method if it's closed. The same happen with any persistent app.

In persistent apps you can use globals, singletons and static properties, but you need to understand that any change will be persistent. So you need to clear before new requests and use closures in the singletons.

In the Techempower benchmark we use normal PDO without persistent connection. But we have always that connection open.
Not only we have the connection open, we also have the prepared statements open and ready to call.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants