ostrolucky / stdinho
将任何 STDIN/STDOUT 转换为 HTTP 服务器
0.6.1
2022-11-12 09:32 UTC
Requires
- php: >=8.0
- ext-fileinfo: *
- ext-json: *
- amphp/amp: ^2.0
- amphp/byte-stream: ^1.2.5
- amphp/socket: ^1
- jean85/pretty-package-versions: ^2.0
- psr/log: >=2.0
- symfony/console: >=4.1
Requires (Dev)
- amphp/dns: ^1
- amphp/http-client: ^4
- amphp/parallel: ^1.0.1
- amphp/process: ^1.0.3
- phpunit/php-code-coverage: >=9.0
- phpunit/phpcov: >=5.0
- phpunit/phpunit: >=7.5
README
stdinho
是一个小型命令行工具,可以创建 TCP 服务器,接受任何 STDOUT 作为其 STDIN,任何连接到服务器的用户都将获得这些数据作为 HTTP 响应。
该工具是在我经常需要与权限较低的同事共享远程资源时编写的。这通常涉及下载文件、上传文件、发送链接、等待目标完成文件下载、删除文件。在过程的每个阶段,您通常都需要等待。
安装
通过 Composer
composer global require ostrolucky/stdinho
或从 发布 中获取可执行 PHAR 文件
用法
只需将一些数据管道输入即可
echo hello world|stdinho
有关所有选项,请参阅
stdinho --help
特性
- async. 是的,在 PHP 中。没有对客户端同时下载的限制
- 在客户端连接之前将缓冲区保存到临时文件中,因此不会丢失任何时间或数据
- 跨平台:Linux/MacOS/Windows
- 检测 MIME 类型并将其附加到 HTTP 响应
- 显示缓冲和客户端下载状态的精美进度条。
示例
视频流
# Server $ stdinho 0.0.0.0:1337 < /file/to/a/movie.mp4 # Client $ firefox http://127.0.0.1:1337
简单的单向聊天
# Server # Server (broadcaster) $ { while read a; do echo $a; done }|bin/stdinho 127.0.0.1:1337 # Client curl 127.0.0.1:1337
实时查看应用程序日志
# Server $ tail -f project/var/log/*.log|stdinho 0.0.0.0:1337 # Client $ curl 127.0.0.1:1337 # Bonus: gzip transfer encoding (server) $ tail -f project/var/*.log|gzip -c|stdinho 0.0.0.0:1337 --http-headers='["Content-Type: text/plain", "Content-Encoding: gzip", "Transfer-Encoding: gzip"]'
流式传输文件夹,包括压缩
# Server $ zip -qr - project|stdinho 0.0.0.0:1337 -f project.zip # Client $ curl 127.0.0.1:1337 -o project.zip # Saves it to project.zip
在中间人的帮助下,动态地将远程数据库导出并流式传输到不同的数据库
# Server $ ssh admin@example.com "mysqldump -u root -ptoor database|gzip -c"|stdinho 0.0.0.0:1337 -f "$(date).sql.gz" # also saves the backup locally # Client $ curl 127.0.0.1:1337|gunzip|mysql -u root -ptoor database # Import it directly to local DB
从本 README 中的 GIF 中的用例
# There is bad connectivity between A (public server) and B (user connected to network via special VPN), # but good connectivity between A and C (on same local network as A, but not public). # However, B and C are behind NAT in separate networks, so there is no direct connection between them. # Here D is introduced, which is public server having good connection to both C and B, but no connection to A. # In final, download stream goes like this: A -> C -> D -> B which bypasses connection problem between A and B and NAT issue at the same time # This problem is basically animation shown in introduction of this README. # C: $ ssh -NR \*:1337:localhost:1337 D #Reverse tunnel. Note: GatewayPorts cannot be set to "no" in D's sshd_config $ curl http://A.com/big_file.tar.gz|stdinho 0.0.0.0:1337 # B: $ curl D:1337 -o big_file.tar.gz
许可
GPLv3 许可证。有关更多信息,请参阅 许可文件。