synapse/php-shell
Composer 安装命令:
composer require synapse/php-shell
包简介
PHP wrapper for executing shell commands
README 文档
README
Introduction
PHP Shell was written to provide an OOP wrapper around shell command execution in PHP. It enables you to receive a response object from the command execution containing the stdout, stderr and exit code of the command.
Documentation
Basic usage
To create the command, pass an absolute path to the command for instantiation. You can also set where the command is executed using the setWorkingDirectory method.
$pwd = new Neuron\Shell\Command('/bin/pwd'); // CommandNotFoundException if the command is not executable $pwd->setWorkingDirectory('/tmp'); // DirectoryDoesNotExistException if the directory is not found $output = $pwd->execute(); var_dump($output->getStdout()); // string(5) "/tmp" var_dump($output->getStderr()); // string(0) "" var_dump($output->getExitCode()); // int(0)
Adding flags
$cmd = new Neuron\Shell\Command('/usr/local/bin/my_command'); $cmd->addShortFlag('v'); $cmd->addShortFlag('c', '/tmp/test.json'); $cmd->addLongFlag('version'); $cmd->addLongFlag('config', '/tmp/test.json');
Adding Arguments
$echo = new Neuron\Shell\Command('/bin/echo'); $echo->addArgument('hi there!');
Piping through another command
$cmd = new Neuron\Shell\Command('/usr/local/bin/my_command'); $cmd2 = new Neuron\Shell\Command('/usr/local/bin/my_command2'); $cmd->pipe($cmd2); echo $cmd->getCmdString(); // "/usr/local/bin/my_command | /usr/local/bin/my_command2"
Searching Output
Check if the command was successful using the wasSuccessful method. Check if the output contains a certain string using the stdoutContains and stderrContains methods.
$echo = new \Neuron\Shell\Command('/bin/echo'); $echo->addArgument('fruit banana'); $output = $echo->execute(); var_dump($output->wasSuccessful()); // bool(true) var_dump($output->stdoutContains('apple')); // bool(false) var_dump($output->stdoutContains('banana')); // bool(true)
License
PHP Shell is open-sourced software licensed under the MIT license
Changelog
1.1.1
- Adding README info for pipe functionality
1.1.0
- Adding pipe functionality
1.0.0
- Initial Release
synapse/php-shell 适用场景与选型建议
synapse/php-shell 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 340 次下载、GitHub Stars 达 2, 最近一次更新时间为 2016 年 04 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 synapse/php-shell 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 synapse/php-shell 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 340
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 11
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-04-15