How to safely maintain a persistent SSH connection in PHP?

I am currently working on a VPS panel that uses a master-slave model. One main server launches a panel written in PHP and manages several subordinate servers via SSH. Access to slave servers is through a limited account, which can be subordinate to certain server administration commands, and all interactions are registered in a directory to which the account itself does not have access.

I am currently using PHP-SSH2, but this approach has several problems:

  • Exit codes are not reliably returned, so all commands must be executed in a shell script that wraps stdout, stderr and the exit code in a JSON object and returns it via stdout. This script must exist on every slave server.
  • The PHP-SSH2 library does not know the term “user connection timeout”, which means that I have to examine the server using fsockopen before trying to use PHP-SSH2 to connect - if I do not, an unavailable server can delay pageload for minutes or more. This is even worse due to the following problem.
  • Persistent connections are not possible. This causes a completely funny pageload time in the panel, especially in combination with the previous timeout problem.

Now I am trying to solve the last problem in the first place.

, , - :

  • PHPSecLib, PHP SSH fsockopen pfsockopen. , , , PHP .
  • SSH- ( localhost) , , . . -, , . , - , , " ", . .
  • , SSH . SSH- Python ( , ), , , paramiko. paramiko , , , paramiko.

:

  • . PHP, , , , . , , , , .
  • Twisted " ". Twisted - , , paramiko.
  • HTTP- , SSH, .

pageload , pageload. VPS.

- , , PHP-SSH2. , ?

+5
2

autossh (portforward) autossh. php- ssh-. ssh autossh . php- .

+1

3, PHP? , .

FIFO .

0

All Articles