Download the PHP package graze/telnet-client without Composer
On this page you can find all versions of the php package graze/telnet-client. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download graze/telnet-client
More information about graze/telnet-client
Files in graze/telnet-client
Package telnet-client
Short Description Telnet client written in PHP
License MIT
Homepage https://github.com/graze/telnet-client
Informations about the package telnet-client
telnet-client
A telnet client written in PHP
Install
Via Composer
Usage
Instantiating a client
Use the factory
method to return a TelnetClientInterface
instance:
Issuing commands
Connect to the remote endpoint using the connect
method:
Once connected, the execute
method can be used to write $command
to the socket:
Responses
Once a command has been sent, the socket is read until a specific sequence is encountered. This is a line ending immediately preceded by either a prompt, or an error prompt.
At this point the execute
method returns a TelnetResponseInterface
object:
A success response object might look like:
Or if the server responded with an error:
Note: responseText
and promptMatches
are trimmed of line endings.
Client configuration
The client uses the following defaults:
- standard prompt
$
- error prompt
ERROR
- line endings
\n
Custom configuration can be passed to the connect
method like so:
The client's global $prompt
can be temporarily overridden on a per-execute basis:
Complex prompts
Some operations may respond with a more complex prompt. These instances can be handled by using a regular expression to match the prompt.
For instance, a server may respond with ERROR n
(where n is an integer) when an error condition is encountered. The client could be configured as such:
An error response would look like:
We can take the regex one further by using a named capturing group, this makes the error code easily available to us in the $promptMatches
array.
which gives us:
Note: it's important to escape any characters in your regex that may have special meaning when interpreted by preg_match.
Socket settings
For timeouts and more, PHP's socket_set_option
is exposed via
See clue/php-socket-raw and socket_set_option for more info.
Change log
Please see CHANGELOG for more information what has changed recently.
Testing
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
Inspired by
Based on bestnetwork/Telnet.
Credits
- John Smith
- Bestnetwork [email protected]
- Dalibor Andzakovic [email protected]
- Marc Ennaji
- Matthias Blaser [email protected]
- Christian Hammers [email protected]
- All Contributors
License
The MIT License (MIT). Please see License File for more information.