Download the PHP package cpehub/php-telnet without Composer
On this page you can find all versions of the php package cpehub/php-telnet. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download cpehub/php-telnet
More information about cpehub/php-telnet
Files in cpehub/php-telnet
Package php-telnet
Short Description PHP Telnet Client
License MIT
Homepage https://github.com/cpehub/php-telnet
Informations about the package php-telnet
php-telnet
A standards-compliant Telnet client for PHP.
php-telnet speaks the Telnet protocol correctly: it escapes IAC per RFC 854/855,
negotiates options with the RFC 1143 "Q Method" state machine, and answers the
server's negotiation automatically while you wait for a prompt. It ships with a
pluggable transport layer (raw sockets by default, or streams with optional TLS).
Upgrading from v1? The behaviour changed in a few important ways (most notably
timelimitis now in milliseconds). See Upgrading from v1 to v2.
Requirements
- PHP 8.2+
ext-sockets(used by the default transport)psr/log(pulled in automatically by Composer)
Installation
Basic usage
sendMessage() waits for the configured prompt pattern and returns the clean
response text (Telnet protocol bytes are stripped for you).
Advanced usage
Build and exchange raw command sequences with CommandSequence:
Note:
CommandSequence::compile()doublesIAC(0xFF) bytes in text and subnegotiation parameters as required by RFC 854/855 — pass raw bytes and let the library escape them; do not double0xFFyourself.
TLS ("telnets")
The default transport uses raw sockets. For an encrypted connection, inject a
StreamTransport created via its tls() named constructor (port 992 by default):
Logging
Pass any PSR-3 LoggerInterface to the constructor, or set it later:
Credentials are never logged: login() sends the password through a redacted
path, so the log shows send: <redacted> instead of the raw bytes.
Exceptions
All exceptions extend Cpehub\Telnet\Exceptions\TelnetException:
Cpehub\Telnet\Exceptions\ConnectionException— connection/transport failures (invalid host/port, connect error, peer closed the connection).Cpehub\Telnet\Exceptions\ProtocolException— malformed Telnet stream (e.g. a danglingIAC, a truncated negotiation or an unterminated subnegotiation).
Catching TelnetException still catches everything. Exception messages no longer
embed buffer contents (a security hardening change); use the value returned by the
send*/await* methods to read the response.
Class synopsis
Cpehub\Telnet\Client
Cpehub\Telnet\Components\CommandSequence
Cpehub\Telnet\Components\Command constants
See https://www.rfc-editor.org/rfc/rfc854 for details.
Cpehub\Telnet\Components\Option constants
Cpehub\Telnet\Components\Printer constants
Upgrading from v1 to v2
v2.0.0 is the first substantial release since v1.0.2. Public method signatures
are preserved, but three behavioural contracts changed. Read this before you
composer update.
| # | Change | v1.0.2 | v2.0.0 | What to do |
|---|---|---|---|---|
| A | timelimit unit |
seconds | milliseconds | Multiply your old second values by 1000. new Client($ip, 23, 5) meant 5 s in v1; in v2 it means 5 ms — use 5000. The default is unchanged in effect (1 s → 1000 ms). Applies to the constructor and the per-call $timelimit in sendMessage()/awaitSequence()/awaitPrompt(). |
| B | CommandSequence::compile() escapes IAC |
raw 0xFF passed through |
0xFF doubled in data and SB params (RFC 854/855) |
Stop doubling 0xFF yourself; pass raw bytes and let the library escape them. |
| C | login() rewritten |
fixed WILL/DO burst + canned reply; waited for the literal string 'Password:' |
negotiation handled automatically by the read loop; password prompt matched with ~password[: ]*$~i (case-insensitive, anchored) |
Usually nothing. If you relied on the old negotiation choreography, review it. Make sure a prompt pattern is configured (see D). |
| D | awaitPrompt() validates the pattern |
passed empty/null to preg_match and looped |
throws TelnetException when no pattern is configured/passed, or when the regex is invalid |
Call setPromptPattern('...') or pass a pattern explicitly. |
| E | New Composer requirements | only php: ^8.2 |
adds ext-sockets and psr/log |
Ensure ext-sockets is enabled. psr/log is pulled in automatically (in v1 it was missing and the autoload could fatal). |
| F | setLogger() fixed |
infinite recursion (stack overflow on first call) | assigns the logger | Nothing — it just works now. |
| G | Constant renamed | Command::ABOUT_OUTPUT |
Command::ABORT_OUTPUT (old name kept as a deprecated alias, same value 0xF5) |
Migrate to Command::ABORT_OUTPUT. |
| H | No buffer in errors/logs | exception messages/logs embedded the raw buffer | messages omit buffer contents (security hardening) | If you parsed exception text to recover the response body, use the value returned by the send*/await* methods instead. |
Additive (non-breaking) improvements you can adopt:
sendSequence(CommandSequence $sequence, bool $sensitive = false)— passtrueto redact a sequence from logs.- New options
Option::TRANSMIT_BINARY(0x00) andOption::END_OF_RECORD(0x19). - Typed exceptions
ConnectionExceptionandProtocolException(both extendTelnetException). - Optional TLS via
StreamTransport::tls()(see TLS). - New optional constructor arguments:
$transport,$policy,$maxBuffer.