Comments (5)
In-so-far as socket tests go isConnected()
does this:
is_resource($this->fsock) && !feof($this->fsock)
If feof()
isn't returning true when a server is restarted then one could argue that that's a PHP problem but tbh idk. https://stackoverflow.com/a/1321716/569976 suggests that an end-of-file usually means that the other side has closed the connection but that doesn't mean that it sole way to verify the closure of a connection. In theory something like ping()
could be done. ping()
tries to send a channel open request and then immediately closes it. If it's unable to do so it reconnects.
One problem with ping()
is that, technically, if a server only supports one channel (eg. some routers), and you're in the middle of an interactive shell or the middle of an SFTP session, then the failure of ping()
doesn't necessarily mean that you've been disconnected.
I suppose an SSH_MSG_IGNORE could be sent, instead. That one wouldn't require a response from the server but it's easy to imagine scenarios wherein the server would have still "closed" the connection even if the client was able to successfully send packets (phpseclib's setKeepAlive()
sends out SSH_MSG_IGNORE messages with some caveats).
Really, I don't think there's a perfect way to implement isConnected()
and, tbh, as is, I think it's roughly equivalent to a wife asking her husband "is the front door locked?". Is the husband supposed to go home, every time she asks, and physically turn the handle to make sure the door is locked, or should he just be able to say it based on the information that he currently has? I mean, technically, even if the husband did lock the door when he left what if, say, that couples 10yo kid decided to unlock the door, check the mail or some such, and then forgot to lock it upon reentry? Expecting the husband to go back to the house to verify the physical condition of the door knob every time he's asked, even if he explicitly does remember locking it, is a bit overkill.
What if I add a sendDummyPacket()
method or some such?
from phpseclib.
libssh's ssh_is_connected()
method appears to behave as phpseclib's isConnected()
method:
In fact, phpseclib's isConnected()
method appears to be more solid then libssh's because of phpseclib's doing feof($this->fsock)
whereas libssh doesn't appear to be doing anything comparable to that.
from phpseclib.
I suppose something else I could do is to give isConnected()
a $level
option that defaults to 0.
$level == 0
would mean that phpseclib is performing the test as is.$level == 1
would involve phpseclib sending an SSH_MSG_IGNORE packet$level == 2
would involve phpseclib sending an SSH_MSG_CHANNEL_OPEN packet and then immediately trying to close that packet
from phpseclib.
How does terrafrost@d27429a look to you?
I'll merge it into the 3.0 branch in a few days unless you (or anyone really lol) reply sooner then that with some reason as to why I shouldn't!
(also, I don't like openChannel
/ close_channel
but I can fix that on a different commit; the goal of this commit is to change the behavior is isConnected
- not to make function names more consistent)
from phpseclib.
terrafrost@d27429a has been merged.
from phpseclib.
Related Issues (20)
- a HOT 1
- Server Terminates Connection HOT 8
- add ssh3 support for faster connection HOT 1
- Using OpenSSH private key results in openssl_sign() - supplied key param cannot be coerced into a private key HOT 4
- `SFTP::put()` fails silently with no provided error information if path does not exist HOT 5
- ElGamal ECC encryption HOT 1
- Parse error: syntax error, unexpected 'const' (T_CONST), expecting variable (T_VARIABLE) HOT 5
- openssl_x509_check_private_key always return cert and privatekey mismatch HOT 2
- SSH2 exec crashes while returning data & "Please close the channel (1) before trying to open it again" HOT 9
- Semantic versioning? HOT 13
- Add setPaddable func at the SymmetricKey class? HOT 2
- 2.0.47 is a breaking change | `AES::setKey` interface changed HOT 1
- Server crashes before NET_SSH2_MSG_KEXDH_REPLY HOT 2
- SSH2: Decryption Failures During Read HOT 8
- Load ASN.1 private key to generate an RSA signature HOT 7
- Slow load of a password protected key HOT 7
- Calling verifyPoint on EC curves throws TypeError HOT 6
- Error reading channel data (7) HOT 4
- How to make SSH2 to behave like ssh HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from phpseclib.