ikarus / sps-client
v0.2.2
2020-07-01 09:37 UTC
Requires
- php: ^7.2
README
客户端包是一个独立的库,用于通过 Unix 套接字或 tcp/ip 连接到服务。
它主要是设计用来与运行中的 sps 进行通信,但你可以在任何地方使用它。
安装
$ composer require ikarus/sps-client
用法
<?php use Ikarus\SPS\Client\UnixClient; use Ikarus\SPS\Client\Command\Command; $client = new UnixClient('/tmp/ikarus-sps.sock'); $response = $client->sendCommand($cmd = new Command('status', ['battery', 'power', 'problems'])); if($response == $client::STATUS_OK) { echo $cmd->getResponse(); // Whatever your sps answered } else { echo "Failed to execute command"; }
要使用 tcp/ip 客户端,更改 $client
<?php use Ikarus\SPS\Client\TcpClient; $client = new TcpClient('192.168.1.100', 8686); // ...