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
-
1Why would you want such a thing?Dharman– Dharman ♦2023-02-08 12:07:00 +00:00Commented Feb 8, 2023 at 12:07
-
1You 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?KIKO Software– KIKO Software2023-02-08 12:10:25 +00:00Commented 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)Your Common Sense– Your Common Sense2023-02-08 12:52:25 +00:00Commented 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.Your Common Sense– Your Common Sense2023-02-08 12:56:56 +00:00Commented Feb 8, 2023 at 12:56
-
1Yes 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.Dharman– Dharman ♦2023-02-09 09:37:32 +00:00Commented Feb 9, 2023 at 9:37
|
Show 4 more comments