azurre/php-shell
Composer 安装命令:
composer require azurre/php-shell
包简介
A convenient none blocking asynchronous shell
README 文档
README
This small and easy to use PHP shell make it able to run commands as non blocking asynchronous jobs
Installation
Install composer in your project:
curl -s https://getcomposer.org/installer | php
Require the package with composer:
composer require azurre/php-shell
Usage
Simple example
$loader = require_once __DIR__ . '/vendor/autoload.php'; use Azurre\Component\System\Shell; $cmd = 'ls -lwa /tmp'; echo Shell::create()->run($cmd);
Output
total 180
drwxrwxrwt 11 root root 4096 Jul 4 23:21 .
drwxr-xr-x 22 root root 4096 Jun 10 16:23 ..
drwxrwxrwt 2 root root 4096 Jun 10 16:23 .ICE-unix
drwxrwxrwt 2 root root 4096 Jun 10 16:23 .X11-unix
drwxrwxrwt 2 root root 4096 Jun 10 16:23 .XIM-unix
drwxrwxrwt 2 root root 4096 Jun 10 16:23 .font-unix
-rw------- 1 www-data www-data 0 Jul 1 21:21 239315d1a4f341c8b52.14168329mUCCHL
-rw-r--r-- 1 www-data www-data 6468 Jul 1 21:18 416205d1a4e5fe8e166.51692428EFpYWQ
-rw-r--r-- 1 www-data www-data 6469 Jul 1 21:21 443675d1a4f3ce6efd0.08860101uETZWS
-rw-r--r-- 1 www-data www-data 6416 Jul 1 21:26 494485d1a503c71cfd8.3817705715MVk4
-rw-r--r-- 1 www-data www-data 6468 Jul 1 21:19 519335d1a4eba5a2ef8.14398347CWkGkb
-rw------- 1 www-data www-data 0 Jul 1 21:27 575735d1a508060a080.18275551cZg15T
Background tasks
$shell = new Shell; $shell->runAsync('ping -c 5 127.0.0.1'); echo "Start background task\n"; while($shell->isProcessRunning()) { echo 'Working...' .PHP_EOL; sleep(1); } echo $shell;
Output
Start background task
Working...
Working...
Working...
Working...
Working...
PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.020 ms
64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.022 ms
64 bytes from 127.0.0.1: icmp_seq=3 ttl=64 time=0.015 ms
64 bytes from 127.0.0.1: icmp_seq=4 ttl=64 time=0.023 ms
64 bytes from 127.0.0.1: icmp_seq=5 ttl=64 time=0.019 ms
--- 127.0.0.1 ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4099ms
rtt min/avg/max/mdev = 0.015/0.019/0.023/0.006 ms
Error handling
$shell = new Shell; $shell->run('ls /A/1/2/3/4')->waitForProcess(); if ($shell->getExitCode() !== Shell::NO_ERROR) { echo "\nExit code: {$shell->getExitCode()}\n"; echo "Error: {$shell->getStdError()}\n"; } else { echo $shell->getStdOut(); }
Output
Exit code: 2
Error: ls: cannot access '/A/1/2/3/4': No such file or directory
License
azurre/php-shell 适用场景与选型建议
azurre/php-shell 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 140 次下载、GitHub Stars 达 0, 最近一次更新时间为 2017 年 03 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「process」 「shell」 「linux」 「async」 「asynchronous」 「cmd」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 azurre/php-shell 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 azurre/php-shell 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 azurre/php-shell 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Doctrine implementation of the MetaborStd (Statemachine) for PHP 8.2+
Brotli binary provided by google/brotli and compiled for amd64
AMWSCAN (Antimalware Scanner) is a php antimalware/antivirus scanner console script written in php for scan your project. This can work on php projects and a lot of others platform.
Advanced local development experience for Linux.
Shell command module for PHP.
PHP library for the MUMSYS project
统计信息
- 总下载量: 140
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 6
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-03-11