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

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

sormagec/binary-driver
======================

A set of tools to build binary drivers

3.0.1(8y ago)2341MITPHPPHP &gt;=5.5

Since Apr 23Pushed 8y ago1 watchersCompare

[ Source](https://github.com/bsormagec/BinaryDriver)[ Packagist](https://packagist.org/packages/sormagec/binary-driver)[ RSS](/packages/sormagec-binary-driver/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (5)Versions (19)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/039a7739b25978d0b2c557a6c09bc9dc35084ec6438a582b6389971c40537e48/68747470733a2f2f7472617669732d63692e6f72672f616c6368656d792d66722f42696e6172794472697665722e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/alchemy-fr/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 Alchemy\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 `Alchemy\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 Alchemy\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 Alchemy\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 Alchemy\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 Alchemy\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

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 86.8% 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 ~112 days

Recently: every ~189 days

Total

17

Last Release

2962d ago

Major Versions

1.6.0 → 2.0.02018-02-20

2.0.0 → 3.0.02018-02-20

1.7 → 3.0.12018-03-30

PHP version history (2 changes)1.0.0PHP &gt;=5.3.3

1.6.0PHP &gt;=5.5

### Community

Maintainers

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

---

Top Contributors

[![romainneutron](https://avatars.githubusercontent.com/u/137574?v=4)](https://github.com/romainneutron "romainneutron (59 commits)")[![aztech-dev](https://avatars.githubusercontent.com/u/93562568?v=4)](https://github.com/aztech-dev "aztech-dev (3 commits)")[![pascalbaljet](https://avatars.githubusercontent.com/u/8403149?v=4)](https://github.com/pascalbaljet "pascalbaljet (2 commits)")[![QuingKhaos](https://avatars.githubusercontent.com/u/993350?v=4)](https://github.com/QuingKhaos "QuingKhaos (1 commits)")[![jhedstrom](https://avatars.githubusercontent.com/u/76833?v=4)](https://github.com/jhedstrom "jhedstrom (1 commits)")[![cb8](https://avatars.githubusercontent.com/u/10119913?v=4)](https://github.com/cb8 "cb8 (1 commits)")[![jens1o](https://avatars.githubusercontent.com/u/11234139?v=4)](https://github.com/jens1o "jens1o (1 commits)")

---

Tags

driverbinary

###  Code Quality

TestsPHPUnit

### Embed Badge

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

```
[![Health](https://phpackages.com/badges/sormagec-binary-driver/health.svg)](https://phpackages.com/packages/sormagec-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.9k17](/packages/civicrm-civicrm-core)[contao/core-bundle

Contao Open Source CMS

1231.6M2.3k](/packages/contao-core-bundle)[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)

PHPackages © 2026

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