简体   繁体   中英

How to Share a MySQL connection between 2 different PHP Processes

I have an unusual case, my website runs two totally different PHP process through a sandbox. I have the normal website running through fastcgi and in the middle that fastcgi process executes one sandboxed script through cli. Both those processes require a MySQL connection and I was wandering if there is a way to share that connection since when the sandboxed script is running the fastcgi is just waiting for it to finish so there would be no concurrency.

This would greatly improve my hardware capability since I would only need one MySQL connection per client unlike the two connections that I need at the moment.

I could always code some kind of multiplexing proxy for this effect but is there any run of the mill solution? I would really appreciate.

Regards.

use database connection pooling middleware or proxy

sqlrelay

mysql-proxy

proxysql

It might be worth having a look at Persistent Connections for this. Basically the connection would be automatically re-used if it exists. Note that this is referring to the resource itself, it does not persist any state from one process to the other.

Before making the decision to use Persistent Connections you should be aware of the pitfalls when used incorrectly. See this question .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM