简介:
今天给大家带来在多台远程机器上并行运行的命令行的PHP库,我们下面来看一段代码。<?php
namespace League\Shunt;
use League\Shunt\Contracts\SCPInterface;
use League\Shunt\Contracts\SessionInterface;
use League\Shunt\BaseObject;
use Symfony\Component\Console\Output\OutputInterface;
use RuntimeException;
class SCP extends BaseObject implements SCPInterface
{
protected $session;
public function __construct(SessionInterface $session, OutputInterface $output)
{
// Set the base object properties
parent::__construct($session, $output);
if ( ! $session->valid()) throw new RuntimeException('SSH connection failed.');
$this->session = $session;
}
public function put($localFile = '', $remoteFile = '')
{
return $this->doRun(__METHOD__, func_get_args(), ssh2_scp_send($this->session->getConnection(), $localFile, $remoteFile));
}
public function get($remoteFile = '', $localFile = '')
{
return $this->doRun(__METHOD__, func_get_args(), ssh2_scp_recv($this->session->getConnection(), $remoteFile, $localFile));
}
}