Satake
Satake

Reputation: 883

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.

Upvotes: 2

Views: 1860

Answers (2)

huhushow
huhushow

Reputation: 547

use database connection pooling middleware or proxy

sqlrelay

mysql-proxy

proxysql

Upvotes: 4

phpPhil
phpPhil

Reputation: 926

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.

Upvotes: 2

Related Questions