Download the PHP package tomcan/ssh-tasks without Composer
On this page you can find all versions of the php package tomcan/ssh-tasks. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package ssh-tasks
PHP SSH Task executor
The PHP SSH Task executor (or ssh-tasks) is a library that allows you to execute commands/scripts over a remote SSH connection from PHP using the ssh2 extention.
Installation and usage
You can install the library through composer. Then include the autoloader as usual.
Authentication
You can authenticate to the remote server using several different authentication schemes. You can do this by passing an
array of associative arrays with the the type
key set to one of the options below.
none
Uses none
authentication. Should hopefully not work, but it is supported. Although ssh_auth_none
returns a list
of supported authentication methods by the server, this value is not passed back or used by the library.
password
When using password
authentication, the value of the password
field in the array will be used as the password for
ssh password authentication.
agent
When using agent
authentication, PHP will try and use the users' ssh-agent active on the machine.
pubkey
When using the pubkey
type, you need to specify both the public as private keys to use for authentication. You can do
this by passing the respective paths using the pubkey
and privkey
keys in the array. If the private key file is
protected with a passphrase, you can pass that passphrase using the passphrase
key.
Using multiple authentication methods
You can add multiple elements to the authentication methods array. The library will try them in the order they appear in the array, and stops after the first successful method. Note that SSH servers will often close the connection when too many authentication attempts have been made.
Output
The library supports multiple ways of dealing with the output of the SSH command. You can control this by setting the
outputMode
parameter on the SshTask::execute()
method. This parameters defaults to log
.
Order of the output
When dealing with multiple output stream (stdout and stderr), the order in which they are read is not guaranteerd as you can't read both streams at exactly the same time. It is possible that output to stdout or stderr is processed in a different order than what the output of the command in an actual terminal would be. This is definitely the case when executing commands that output a lot of data on both streams at the same time.
log
When using the log
the output mode, every successful read from either the stdout of stderr steam is added to an
array where every element contains the timestamp, stream name, and actual data read.
split
When using the split
output type, the output array will contain 2 elements. Element 0 will contain the concatenated
output for stdout, where element 1 contains the concatenated output of stderr.
combined
When using the combined
output type, the command is wrapped in a function with stderr redirected to stdout. It further
functions in the same way as split
, but will not have any output in the second element. Since the output redirection
works on the server side, the stdout/stderr output typically always is in the correct order, but you can't tell apart
stdout from stderr.
callback
When using the callback
output type, you can specify a callback function instead of storing the output in an array.
This allows you to receive the output while the command is still running, which can be useful for getting feedback from
long running commands.
The function will be called using call_user_func
and you can set a callback for the output and error stream.
Would result in:
All versions of ssh-tasks with dependencies
ext-ssh2 Version *