PHPackages                             sura/binary-driver - 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. sura/binary-driver

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

sura/binary-driver
==================

A set of tools to build binary drivers

1.0.0(4y ago)081MITPHPPHP &gt;=8.0

Since Jan 30Pushed 4y agoCompare

[ Source](https://github.com/Sura-framework/BinaryDriver)[ Packagist](https://packagist.org/packages/sura/binary-driver)[ RSS](/packages/sura-binary-driver/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (4)Versions (2)Used By (1)

Binary Driver
=============

[](#binary-driver)

Binary-Driver is a set of PHP tools to build binary drivers.

[![Build Status](https://camo.githubusercontent.com/85006e5a8af680ce3431bae4deb622896f9a7b7bab9599ece9923a52b31e65b7/68747470733a2f2f7472617669732d63692e6f72672f737572612f42696e6172794472697665722e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/sura/BinaryDriver)

Why ?
-----

[](#why-)

You may wonder *Why building a library while I can use `exec` or [symfony/process](https://github.com/symfony/Process) ?*.

Here is a simple answer :

- If you use `exec`, `passthru`, `system`, `proc_open` or any low level process handling in PHP, you should have a look to [symfony/process](https://github.com/symfony/Process)component that will provide an OO portable, testable and secure interface to deal with this. It seems easy at first approach, but if you look at this component [unit tests](https://github.com/symfony/Process/tree/master/Tests), you will see that handling process in a simple interface can easily become a nightmare.
- If you already use symfony/process, and want to build binary drivers, you will always have the same common set of methods and objects to configure, log, debug, and generate processes. This library is a base to implement any binary driver with this common set of needs.

AbstractBinary
--------------

[](#abstractbinary)

`AbstractBinary` provides an abstract class to build a binary driver. It implements `BinaryInterface`.

Implementation example :

```
use Sura\BinaryDriver\AbstractBinary;

class LsDriver extends AbstractBinary
{
    public function getName()
    {
        return 'ls driver';
    }
}

$parser = new LsParser();

$driver = Driver::load('ls');
// will return the output of `ls -a -l`
$parser->parse($driver->command(array('-a', '-l')));
```

### Binary detection troubleshooting

[](#binary-detection-troubleshooting)

If you are using Nginx with PHP-fpm, executable detection may not work because of an empty `$_ENV['path']`. To avoid having an empty `PATH` environment variable, add the following line to your `fastcgi_params`config file (replace `/your/current/path/` with the output of `printenv PATH`) :

```
fastcgi_param    PATH    /your/current/path

```

Logging
-------

[](#logging)

You can log events with a `Psr\Log\LoggerInterface` by passing it in the load method as second argument :

```
$logger = new Monolog\Logger('driver');
$driver = Driver::load('ls', $logger);
```

Listeners
---------

[](#listeners)

You can add custom listeners on processes. Listeners are built on top of [Evenement](https://github.com/igorw/evenement)and must implement `Sura\BinaryDriver\ListenerInterface`.

```
use Symfony\Component\Process\Process;

class DebugListener extends EventEmitter implements ListenerInterface
{
    public function handle($type, $data)
    {
        foreach (explode(PHP_EOL, $data) as $line) {
            $this->emit($type === Process::ERR ? 'error' : 'out', array($line));
        }
    }

    public function forwardedEvents()
    {
        // forward 'error' events to the BinaryInterface
        return array('error');
    }
}

$listener = new DebugListener();

$driver = CustomImplementation::load('php');

// adds listener
$driver->listen($listener);

$driver->on('error', function ($line) {
    echo '[ERROR] ' . $line . PHP_EOL;
});

// removes listener
$driver->unlisten($listener);
```

### Bundled listeners

[](#bundled-listeners)

The debug listener is a simple listener to catch `stderr` and `stdout` outputs ; read the implementation for customization.

```
use Sura\BinaryDriver\Listeners\DebugListener;

$driver = CustomImplementation::load('php');
$driver->listen(new DebugListener());

$driver->on('debug', function ($line) {
    echo $line;
});
```

ProcessBuilderFactory
---------------------

[](#processbuilderfactory)

ProcessBuilderFactory ease spawning processes by generating Symfony \[Process\] () objects.

```
use Sura\BinaryDriver\ProcessBuilderFactory;

$factory = new ProcessBuilderFactory('/usr/bin/php');

// return a Symfony\Component\Process\Process
$process = $factory->create('-v');

// echoes '/usr/bin/php' '-v'
echo $process->getCommandLine();

$process = $factory->create(array('-r', 'echo "Hello !";'));

// echoes '/usr/bin/php' '-r' 'echo "Hello !";'
echo $process->getCommandLine();
```

Configuration
-------------

[](#configuration)

A simple configuration object, providing an `ArrayAccess` and `IteratorAggregate`interface.

```
use Sura\BinaryDriver\Configuration;

$conf = new Configuration(array('timeout' => 0));

echo $conf->get('timeout');

if ($conf->has('param')) {
    $conf->remove('param');
}

$conf->set('timeout', 20);

$conf->all();
```

Same example using the `ArrayAccess` interface :

```
use Sura\BinaryDriver\Configuration;

$conf = new Configuration(array('timeout' => 0));

echo $conf['timeout'];

if (isset($conf['param'])) {
    unset($conf['param']);
}

$conf['timeout'] = 20;
```

License
-------

[](#license)

This project is released under the MIT license.

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity54

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

1569d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6cdac9e4390ea15486f926c4a89f4c02020954be51c17d5886299b5b83d75ecf?d=identicon)[semyon492](/maintainers/semyon492)

---

Top Contributors

[![semyon492](https://avatars.githubusercontent.com/u/22177963?v=4)](https://github.com/semyon492 "semyon492 (2 commits)")

---

Tags

driverbinary

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/sura-binary-driver/health.svg)

```
[![Health](https://phpackages.com/badges/sura-binary-driver/health.svg)](https://phpackages.com/packages/sura-binary-driver)
```

###  Alternatives

[alchemy/binary-driver

A set of tools to build binary drivers

19110.9M39](/packages/alchemy-binary-driver)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

728272.9k20](/packages/civicrm-civicrm-core)[cognesy/instructor-php

The complete AI toolkit for PHP: unified LLM API, structured outputs, agents, and coding agent control

310107.9k1](/packages/cognesy-instructor-php)[comcast/php-legal-licenses

A utility to generate a Licenses file containing the full license text for every dependency in your project for legal purposes.

821.1M9](/packages/comcast-php-legal-licenses)[dbrekelmans/browser-driver-installer

Helps you install the appropriate browser driver.

467.8k](/packages/dbrekelmans-browser-driver-installer)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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