PHPackages                             graze/telnet-client - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. graze/telnet-client

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

graze/telnet-client
===================

Telnet client written in PHP

v2.3.0(5y ago)50233.9k↓15.2%10[2 issues](https://github.com/graze/telnet-client/issues)[1 PRs](https://github.com/graze/telnet-client/pulls)4MITPHPPHP &gt;5.5.0

Since Feb 18Pushed 3y ago15 watchersCompare

[ Source](https://github.com/graze/telnet-client)[ Packagist](https://packagist.org/packages/graze/telnet-client)[ Docs](https://github.com/graze/telnet-client)[ RSS](/packages/graze-telnet-client/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (9)Dependencies (6)Versions (12)Used By (4)

telnet-client
=============

[](#telnet-client)

[![Latest Version on Packagist](https://camo.githubusercontent.com/713b12cd43a36323710c6aa046247321f3a76f913eb87250599093eeb10e6381/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6772617a652f74656c6e65742d636c69656e742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/graze/telnet-client)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![Build Status](https://camo.githubusercontent.com/cb1fa4b4c55de4139150c5e7c9bd0ff6157d5d4acbbc8f4e7477d5324b6d8f48/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6772617a652f74656c6e65742d636c69656e742f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/graze/telnet-client)[![Coverage Status](https://camo.githubusercontent.com/a2aea3141861ff0dd47c02ad17f42e059b088cf8ca9a30db3400432fcb6654a8/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f6772617a652f74656c6e65742d636c69656e742e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/graze/telnet-client/code-structure)[![Quality Score](https://camo.githubusercontent.com/40ed9ce994802e154e0581ab9e587748c93fc04c5ee40b4972830226a85785e3/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6772617a652f74656c6e65742d636c69656e742e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/graze/telnet-client)[![Total Downloads](https://camo.githubusercontent.com/b30104b5ac63c3373b08882ee8f52e43e3ce1a77c52aab8eab001e12be04c9c1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6772617a652f74656c6e65742d636c69656e742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/graze/telnet-client)

A telnet client written in PHP

Install
-------

[](#install)

Via Composer

```
composer require graze/telnet-client
```

Usage
-----

[](#usage)

### Instantiating a client

[](#instantiating-a-client)

Use the `factory` method to return a `TelnetClientInterface` instance:

```
$client = Graze\TelnetClient\TelnetClient::factory();
```

### Issuing commands

[](#issuing-commands)

Connect to the remote endpoint using the `connect` method:

```
$dsn = '127.0.0.1:23';
$client->connect($dsn);
```

Once connected, the `execute` method can be used to write `$command` to the socket:

```
$command = 'Open the pod bay doors, HAL';
$resp = $client->execute($command);
```

### Responses

[](#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:

```
/**
 * Whether an error prompt was encountered.
 *
 * @return bool
 */
public function isError();

/**
 * Any response from the server up until a prompt is encountered.
 *
 * @return string
 */
public function getResponseText();

/**
 * The portion of the server's response that caused execute() to return.
 *
 * @return array
 */
public function getPromptMatches();
```

A success response object might look like:

```
Graze\TelnetClient\TelnetResponse {#2
  #isError: false
  #responseText: "Affirmative, Dave"
  #promptMatches: array:1 [
    0 => "$"
  ]
}
```

Or if the server responded with an error:

```
Graze\TelnetClient\TelnetResponse {#2
  #isError: true
  #responseText: " I'm sorry, Dave. I'm afraid I can't do that"
  #promptMatches: array:1 [
    0 => "ERROR"
  ]
}
```

**Note:** `responseText` and `promptMatches` are trimmed of line endings.

### Client configuration

[](#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:

```
$dsn = '127.0.0.1:23';
$prompt = 'OK';
$promptError = 'ERR';
$lineEnding = "\r\n";
$client->connect($dsn, $prompt, $promptError, $lineEnding);
```

The client's global `$prompt` can be temporarily overridden on a per-execute basis:

```
$command = 'login';
$prompt = 'Username:';
$resp = $client->execute($command, $prompt);
```

### Complex prompts

[](#complex-prompts)

Some operations may respond with a more complex prompt. These instances can be handled by using a [regular expression](http://www.regular-expressions.info) 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:

```
$dsn = '127.0.0.1:23';
$promptError = 'ERROR [0-9]';
$client->connect($dsn, null, $promptError);
```

An error response would look like:

```
Graze\TelnetClient\TelnetResponse {#2
  #isError: true
  #responseText: "unknown command"
  #promptMatches: array:1 [
    0 => "ERROR 6"
  ]
}
```

We can take the regex one further by using a [named capturing group](http://www.regular-expressions.info/named.html), this makes the error code easily available to us in the `$promptMatches` array.

```
$dsn = '127.0.0.1:23';
$promptError = 'ERROR (?[0-9])';
$client->connect($dsn, null, $promptError);
```

which gives us:

```
Graze\TelnetClient\TelnetResponse {#2
  #isError: true
  #responseText: "unknown command"
  #promptMatches: array:3 [
    0 => "ERROR 6",
    "errorNum" => "6",
    1 => "6"
  ]
}
```

**Note:** it's important to escape any characters in your regex that may have special meaning when interpreted by [preg\_match](http://php.net/manual/en/function.preg-match.php).

### Socket settings

[](#socket-settings)

For timeouts and more, PHP's `socket_set_option` is exposed via

```
$client->getSocket()->setOption();
```

See [clue/php-socket-raw](https://github.com/clue/php-socket-raw) and [socket\_set\_option](http://php.net/manual/en/function.socket-set-option.php) for more info.

Change log
----------

[](#change-log)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Testing
-------

[](#testing)

```
make test
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Inspired by
-----------

[](#inspired-by)

Based on [bestnetwork/Telnet](https://github.com/bestnetwork/Telnet).

Credits
-------

[](#credits)

- [John Smith](https://github.com/john-n-smith)
- Bestnetwork
- Dalibor Andzakovic
- Marc Ennaji
- Matthias Blaser
- Christian Hammers
- [All Contributors](https://github.com/graze/telnet-client/contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity47

Moderate usage in the ecosystem

Community26

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 61.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~219 days

Total

9

Last Release

1985d ago

Major Versions

v1.0.0 → v2.0.02016-03-01

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/637788?v=4)[graze.com](/maintainers/graze)[@graze](https://github.com/graze)

---

Top Contributors

[![john-n-smith](https://avatars.githubusercontent.com/u/1314694?v=4)](https://github.com/john-n-smith "john-n-smith (46 commits)")[![brendankay](https://avatars.githubusercontent.com/u/641490?v=4)](https://github.com/brendankay "brendankay (13 commits)")[![biggianteye](https://avatars.githubusercontent.com/u/1482649?v=4)](https://github.com/biggianteye "biggianteye (11 commits)")[![RokasDevelopment](https://avatars.githubusercontent.com/u/13278000?v=4)](https://github.com/RokasDevelopment "RokasDevelopment (4 commits)")[![kinekt4](https://avatars.githubusercontent.com/u/3781991?v=4)](https://github.com/kinekt4 "kinekt4 (1 commits)")

---

Tags

phpclientgrazetelnettelnet-client

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/graze-telnet-client/health.svg)

```
[![Health](https://phpackages.com/badges/graze-telnet-client/health.svg)](https://phpackages.com/packages/graze-telnet-client)
```

###  Alternatives

[bestnetwork/telnet

Telnet client in php

2428.6k](/packages/bestnetwork-telnet)[zoon/rialto

Manage Node resources from PHP

12199.4k3](/packages/zoon-rialto)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
