How to Share a MySQL connection between 2 different PHP Processes

此生再无相见时 提交于 2019-12-08 03:15:20

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!