简体   繁体   English

PHP-SSH隧道到MySQL

[英]PHP - SSH tunnel to MySQL

How to make self destructing SSH tunnel to access MySQL on another server? 如何使自毁SSH隧道访问另一台服务器上的MySQL?

Currently my code looks like: 目前,我的代码如下:

exec('ssh -fNg -L 4343:127.0.0.1:3306 user@remotehost.com');

$mysqli = new mysqli('127.0.0.1', 'dbuser', 'dbpass', 'dbname', '4343');

Problem here is that script hangs after making exec command. 问题在于脚本在执行exec命令后挂起。 How should i execute rest of the script, and how to close background process once the script has finished? 我应该如何执行脚本的其余部分,以及脚本完成后如何关闭后台进程?

So after some research - solution is to add > /dev/null 2>/dev/null & on the end of command. 因此,经过一些研究-解决方案是在命令末尾添加> /dev/null 2>/dev/null &

Complete working example line is: 完整的工作示例行是:

exec('ssh -fNg -L 4343:127.0.0.1:3306 user@remotehost.com > /dev/null 2>/dev/null &');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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