1

Is it possible to make persistent or permanent connection to Mysql in PHP? I mean when I make few separate requests to PHP they all will use the same connection to Mysql. I use msqli driver not sure if it is possible.

9
  • 1
    Why would you want such a thing? Commented Feb 8, 2023 at 12:07
  • 1
    You could possibly do it. See: php.net/manual/en/mysqli.persistconns.php But you must have a VERY GOOD REASON to do so. Do you have one? Commented Feb 8, 2023 at 12:10
  • @KIKOSoftware pconnect allows for a php process to reuse once opened opened connection for the consequent requests. But by no means it allows for a few separate processes to use the same connection [in parallel] which is likely asked in this question (and which is a really bad idea) Commented Feb 8, 2023 at 12:52
  • Only if it's a single php process thet serves all requests by itself (such as a websocket deamon), then obviously this process can use a single database connection for all requests but still it would be a bad idea, and it should rather create its own pool of opened connections. Commented Feb 8, 2023 at 12:56
  • 1
    Yes but it's not worth it. You should look for optimisation opportunities elsewhere. Opening connection is a very fast process. You will have hundreds of other issues if you start using persistent connections. Commented Feb 9, 2023 at 9:37

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.