pbmedia/binary-driver
最新稳定版本:3.0.1
Composer 安装命令:
composer require pbmedia/binary-driver
包简介
A set of tools to build binary drivers
README 文档
README
Binary-Driver is a set of PHP tools to build binary drivers.
Why ?
You may wonder Why building a library while I can use exec or symfony/process ?.
Here is a simple answer :
-
If you use
exec,passthru,system,proc_openor any low level process handling in PHP, you should have a look to 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, 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 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
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
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
You can add custom listeners on processes. Listeners are built on top of 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
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 ease spawning processes by generating Symfony [Process] (http://symfony.com/doc/master/components/process.html) 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
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
This project is released under the MIT license.
pbmedia/binary-driver 适用场景与选型建议
pbmedia/binary-driver 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 224.16k 次下载、GitHub Stars 达 15, 最近一次更新时间为 2026 年 01 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「driver」 「binary」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 pbmedia/binary-driver 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 pbmedia/binary-driver 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 pbmedia/binary-driver 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Galera cluster driver for Doctrine
A PHP client driver for the RethinkDB query language (ReQL)
A PHP Framework that allows you to encode and decode arbitrary ASN.1 structures using the ITU-T X.690 Encoding Rules.
Arikam CMS Driver package
Use a REST API as if it was your local database
Bit I/O library
统计信息
- 总下载量: 224.16k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 15
- 点击次数: 11
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-04