PHPackages                             lifo/remote-control - 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. lifo/remote-control

ActiveLibrary

lifo/remote-control
===================

Remote control for network devices

v1.0(12y ago)31702MITPHPPHP &gt;=5.3.0

Since May 6Pushed 9y ago1 watchersCompare

[ Source](https://github.com/lifo101/remote-control)[ Packagist](https://packagist.org/packages/lifo/remote-control)[ RSS](/packages/lifo-remote-control/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependenciesVersions (2)Used By (0)

Remote Control
==============

[](#remote-control)

"Remote Control" is a PHP class library that allows you to programically control a remote device via its `CLI` interface *(usually via SSH or Telnet)* or any other command via `STDIN` and `STDOUT` using [Expect](http://php.net/manual/en/book.expect.php "PHP Expect") in an easy to use object oriented manner.

I've based this class design on my own [Cisco Automation](http://github.com/lifo101/cisco-automation "Perl library for connecting to Cisco devices via Expect") perl library here on github. However, I've tried to make this library as generic as possible to work with any any process or device.

Development Notes
-----------------

[](#development-notes)

The PHP [Expect](http://php.net/manual/en/book.expect.php "PHP Expect") library is extremely limited and does not even come close to the perl Expect module available on `CPAN`. As of this writing the newest version of [php-expect](http://php.net/manual/en/book.expect.php "PHP Expect") is v0.3.1 *(updated almost 2 years ago!)*. Two main limitations is the way [php-expect](http://php.net/manual/en/book.expect.php "PHP Expect") handles capturing output and pattern matching.

- [php-expect](http://php.net/manual/en/book.expect.php "PHP Expect") supports an INI setting `expect.logfile` to capture output but due to buffering its of limited use in a *real-time* program that wants to read/write to a process. In order to allow for *real-time* output capturing I have to constantly set and reset the `expect.logfile` INI setting during runtime. This causes the the file to flush and the class then intelligently knows where to read from the file to determine output from a previous command. I haven't noticed any performance issues with this so far.
- [php-expect](http://php.net/manual/en/book.expect.php "PHP Expect") says it supports `REGEXP` style patterns but doesn't clearly state if that is truly PREG patterns or not. In my testing certain patterns cause Segfaults or simply do not work the way you're used to. Most notably is you cannot use modifiers *(multi-line: m)* and because of that its a little harder to limit prompt matches, etc.

Project Setup
-------------

[](#project-setup)

### Dependencies

[](#dependencies)

1. PHP 5.3+
2. [Expect](http://php.net/manual/en/book.expect.php "PHP Expect") PECL extension

### Installation

[](#installation)

[Composer](http://getcomposer.org/ "Composer") is the recommended way to download and maintain your copy of the library (using [packagist.org](https://packagist.org/)). Using [Github](http://github.com/ "Github") directly is also a reasonable option, however, you'll have to manually create an autoloader for the classes or `include` them on your own (ugly!)

#### Composer Installation

[](#composer-installation)

1. Add "lifo/remote-control" to your project composer.json file:

    ```
    {
        "require": {
            "lifo/remote-control": "dev-master"
        }
    }
    ```
2. Run composer update: `php composer.phar update lifo/remote-control`

#### GitHub Installatin

[](#github-installatin)

1. Clone the remote-control repository:

    `git clone git://github.com/lifo101/remote-control.git`
2. Add `Lifo/RemoteControl` to your project autoloader as-needed.

Examples
--------

[](#examples)

See the [examples](examples) directory for more runnable examples.

```
use Lifo\RemoteControl\RemoteControl;
use Lifo\RemoteControl\Type\NetworkDevice;

// Raw control object for low level access (see 2nd example for an easier approach)
$rc = new RemoteControl("ssh username@hostname", array(
    'auto_start' => true,
    'log_stdout' => true,
    // more options available
));

// generic prompt for "cisco" devices; your milage may vary.
$prompt = '[a-zA-Z0-9._-]+ ?(\(config[^\)]*\))? ?[$#>] ?(\(enable\))? *$';

// wait for output from the process and act upon various patterns.
// Each pattern can be a closure or simple variable. If any closure
// returns true or RemoteControl::WAIT_DONE then the wait loop will end.
$res = $rc->wait(array(
    //    REGEX/GLOB/STR => Closure or mixed value
    array($prompt        => true ),
    array('yes/no\)\?'   => function($rc){ $rc->writeln('yes'); } ),
    array('[Pp]assword:' => function($rc){ $rc->writeln('password'); } ),
));

// attempt another command and wait for prompt
$rc->writeln("show clock");
$rc->wait($prompt);

// ----------------------------------------------------------
// OR ... (this is preferred over the low-level method above)
// ----------------------------------------------------------

// High level control object for easier access of network type devices
$d = new NetworkDevice(array(
    'protocol' => 'ssh',
    'host'     => 'hostname',
    'username' => 'username',
    'password' => 'password',
    'enable'   => 'enablepw',
    // more options ...
    //'remote_control_options' => array(
    //    'log_stdout' => true,
    //)
));
$d->verbose(true); // for debugging/troubleshooting only; same as setting log_stdout = true

// login method handles a lot of variations for different devices and
// will enable if possible. You can call $d->enable() manually too.
if (!$d->login()) {
    die("Error logging in!\n");
}

// basic method to send a command and wait for a prompt. Returns
// any output received after the commmand.
echo $d->send("show version");
```

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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

Unknown

Total

1

Last Release

4392d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/367337?v=4)[Jason M](/maintainers/lifo101)[@lifo101](https://github.com/lifo101)

---

Top Contributors

[![lifo101](https://avatars.githubusercontent.com/u/367337?v=4)](https://github.com/lifo101 "lifo101 (35 commits)")

---

Tags

sshremotenetworkcontrolexpecttelnetcisco

### Embed Badge

![Health badge](/badges/lifo-remote-control/health.svg)

```
[![Health](https://phpackages.com/badges/lifo-remote-control/health.svg)](https://phpackages.com/packages/lifo-remote-control)
```

###  Alternatives

[phpseclib/phpseclib

PHP Secure Communications Library - Pure-PHP implementations of RSA, AES, SSH2, SFTP, X.509 etc.

5.6k434.8M1.3k](/packages/phpseclib-phpseclib)[inpsyde/multilingual-press

Simply THE multisite-based free open source plugin for your multilingual websites.

2414.0k1](/packages/inpsyde-multilingual-press)

PHPackages © 2026

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