gud3/executor

此扩展支持本地和远程文件

维护者

详细信息

github.com/gud3/executor

源代码

问题

安装: 45

依赖项: 0

建议者: 0

安全性: 0

星级: 0

关注者: 1

分支: 0

开放问题: 0

类型:executor

1.1.0-stable 2017-09-18 17:11 UTC

This package is not auto-updated.

Last update: 2024-09-29 03:47:07 UTC


README

此扩展支持本地和远程文件。它可以在控制台模式下运行命令。有两个不同的标志用于执行带响应的命令和不带响应的命令(此时脚本将不会等待执行,模仿异步执行)。有三个公共方法用于与该类一起工作:exec(), getFile(), setFile()。每个函数都有许多输入参数,具体如下所示。要在对象构造函数中连接到ssh2,您需要传递连接数据。

安装

安装此扩展的首选方法是通过 composer

输入运行

php composer.phar require --prefer-dist gud3/executor "*"

或添加

"gud3/executor": ">=1.0.0"

到您的 composer.json 文件的 require 部分。

本地使用

在脚本所在的系统上本地执行命令

$console = (new \gud3\executor\Local())->exec('command');

控制台变量将是执行命令行的结果。对于异步执行(通常用于运行PHP或其他脚本),必须将第二个参数传递为true。

$console = (new \gud3\executor\Local())->exec('command', true);

此外,要执行多个命令,可以将数组传递给函数。然后它们将依次执行。

$console = (new \gud3\executor\Local())->exec(['command1', 'command2']);

使用Ssh2协议

要通过协议连接,您必须输入IP地址、用户名和密码。

$connect = new \gud3\executor\Ssh2($ip, $login, $password, $port);
$console = $connect->exec(['command1', 'command2', 'command3']);

您可以通过以下方式获取文件内容

$local = new \gud3\executor\Local();
$file = $local->getFile($path_to_file, $file_name);

或远程

$local = new \gud3\executor\Ssh2($ip, $login, $password, $port);
$file = $local->getFile($path_to_file, $file_name);

如果文件存在,则覆盖文件。如果文件不存在,则创建它

$result = $local->setFile($path_to_file, $file_name, $content);