问题
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.
回答1:
use database connection pooling middleware or proxy
sqlrelay
mysql-proxy
proxysql
回答2:
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.
来源:https://stackoverflow.com/questions/29224001/how-to-share-a-mysql-connection-between-2-different-php-processes