Answer the question
In order to leave comments, you need to log in
Pseudo-persistent connection in PHP, is it possible?
Good day everyone!
Why "pseudo-persistent"? Because PHP is born to die. That's why I want to find a way, somehow, to keep connections at least for a while.
Now about 500 RPS, and I have to keep ~ 6k connections with PGSQL, I don’t want to use a big timeout. these restrictions are not always good. Tell me, how can I get to ~10? Although okay, at 50 in the connection pool and switch between them on the fly?
PS
it feels like this code doesn't work at all:
new \PDO($dsn, $user, $password, [
\PDO::ATTR_PERSISTENT => true
]);
Answer the question
In order to leave comments, you need to log in
Use pgbouncer.
Best in transaction pool mode. Then the postgresql backend will be issued to connections from the application only for the duration of the transaction. This makes it possible and very efficient to dispose of only a small number of postgresql processes and retain the possibility of transactional work. Prepared statements do not work in transaction mode, but PDO emulates them anyway, so this is not a problem.
pgbouncer easily keeps thousands of open connections with the application, easily opens and closes them, the fun starts when you try to pump through the bouncer with gigabit traffic (and it costs just by launching the second bouncer right there on another port). Usually placed on the machine directly with the base on port 6432.
It is actually the de facto standard for postgresql installations.
Theoretically, reactphp.org
could help you.
In practice, it's hard to say that this will be a 100% solution to your problem.
I would rather look towards either another programming language (Node.JS, Go, Python, Java...) or an extensive method (add additional servers and load balance)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question