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

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

vadimpronin/alchemy-binary-driver
=================================

A set of tools to build binary drivers

5.1.0.2(6y ago)0311MITPHPPHP &gt;=5.5

Since Apr 23Pushed 6y agoCompare

[ Source](https://github.com/vadimpronin/BinaryDriver)[ Packagist](https://packagist.org/packages/vadimpronin/alchemy-binary-driver)[ RSS](/packages/vadimpronin-alchemy-binary-driver/feed)WikiDiscussions master Synced 4w ago

READMEChangelog (2)Dependencies (4)Versions (23)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

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

Top contributor holds 75.6% 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 ~127 days

Recently: every ~122 days

Total

20

Last Release

2345d ago

Major Versions

1.6.0 → 4.1.02018-04-19

v2.0.0 → 5.0.02018-08-06

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

1.6.0PHP &gt;=5.5

4.1.0PHP ~7.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/f1e509cce0fee813195d30bdc525f24ab97018a34d43be9d6377973fe28de147?d=identicon)[vpronin](/maintainers/vpronin)

---

Top Contributors

[![romainneutron](https://avatars.githubusercontent.com/u/137574?v=4)](https://github.com/romainneutron "romainneutron (59 commits)")[![jens1o](https://avatars.githubusercontent.com/u/11234139?v=4)](https://github.com/jens1o "jens1o (6 commits)")[![aztech-dev](https://avatars.githubusercontent.com/u/93562568?v=4)](https://github.com/aztech-dev "aztech-dev (3 commits)")[![CamiloManrique](https://avatars.githubusercontent.com/u/17486602?v=4)](https://github.com/CamiloManrique "CamiloManrique (3 commits)")[![vadimpronin](https://avatars.githubusercontent.com/u/5534215?v=4)](https://github.com/vadimpronin "vadimpronin (3 commits)")[![QuingKhaos](https://avatars.githubusercontent.com/u/993350?v=4)](https://github.com/QuingKhaos "QuingKhaos (1 commits)")[![cb8](https://avatars.githubusercontent.com/u/10119913?v=4)](https://github.com/cb8 "cb8 (1 commits)")[![tacman](https://avatars.githubusercontent.com/u/619585?v=4)](https://github.com/tacman "tacman (1 commits)")[![jhedstrom](https://avatars.githubusercontent.com/u/76833?v=4)](https://github.com/jhedstrom "jhedstrom (1 commits)")

---

Tags

driverbinary

###  Code Quality

TestsPHPUnit

### Embed Badge

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

```
[![Health](https://phpackages.com/badges/vadimpronin-alchemy-binary-driver/health.svg)](https://phpackages.com/packages/vadimpronin-alchemy-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)[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)[balbuf/composer-git-merge-driver

Custom git merge driver to minimize merge conflicts in composer.json and composer.lock files.

137268.0k](/packages/balbuf-composer-git-merge-driver)[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)
