Without calling the ssh tunnel in a separate process, this means that you will need to create a new tunnel for each script call - and you will not be able to use the tunnel created by another instance, since you do not know when it will end. Thus, in addition to the connection overhead, you need to manage the pool of local sockets.
The short answer is that this is simply not possible.
The longer answer is that you can run daemons / long-running processes from PHP, but there are a few caveats . Therefore, if you can use the program execution functions and have access to the POSIX toolkit using command line tools, then this is possible. This will be much easier to implement if you can configure a key pair (with a private private key) to avoid the need for parsing I / O in the program, to enter the password at the right point (or use something like ' expect ' for processing).
source share