how to serialize phpseclib?

北城以北 提交于 2019-12-06 19:43:27

The only way to have a persistent connection is to actually have a script constantly running which is keeping the connection open. Which means you have one script with a never ending while (true) { ... } loop which opens a connection once and keeps it. You then need to find a way to communicate with this script to make it execute commands. AMQP, ØMQ, Gearman, sockets and similar techniques can be employed for that.

Depending on which PHP version you have, you could try to declare a static variable for the ssh connection.

If phpseclib uses pfsockopen it might be able to reuse existing connections - but that is a longshot, and might require modification of the library.

But generally speaking you cannot do what you want in PHP. When the script is finished all open sockets are closed, as the executing process terminates. You certainly can't store it in a session variable - as soon as the Net_SSH2 object goes out of scope it is destroyed.

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