This repository has been archived by the owner on May 5, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
LiquidInterface.php
87 lines (73 loc) · 2.11 KB
/
LiquidInterface.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
class LiquidInterface {
protected $sock;
protected $harbor;
public function __construct() {
}
public function connect(){
$this->sock = fsockopen('localhost',1234,$error,$errstr,10);
if(!$this->sock){
error_log("Error communicating with liquidsoap; $error: $errstr.");
}else{
return true;
}
return false;
}
public function disconnect(){
if($this->sock) {
fclose($this->sock);
}
}
public function __destruct() {
$this->executeCommand('exit');
$this->disconnect();
}
public function getHarborSource(){
if($this->sock) {
preg_match_all('/^(harbor_[0-9]+)/m', $this->executeCommand('list'), $matches);
return $matches[0][0];
}
return null;
}
public function getOutputStreams(){
if($this->sock) {
preg_match_all('/^(.*?) : output/m', $this->executeCommand('list'), $matches);
return $matches[1];
}
return null;
}
public function getOutputStreamStatus($output){
return $this->executeCommand($output.".status");
}
public function startOutputStream($output){
return $this->executeCommand($output.".start");
}
public function stopOutputStream($output){
return $this->executeCommand($output.".stop");
}
public function kickHarbor($source) {
$this->executeCommand($source.".kick");
}
public function getHarborStatus($source) {
return $this->executeCommand($source.".status");
}
public function getUptime() {
return $this->executeCommand('uptime');
}
protected function executeCommand($command){
if(!$this->sock) {
return false;
}
fwrite($this->sock,$command."\n");
$out = '';
$s = '';
while(!feof($this->sock) && !preg_match('/^END/m',$s)){
$s = fgets($this->sock, 4096);
$out .= $s;
}
$out = preg_replace('/END$/', '', trim($out));
$out = trim($out);
return $out;
}
}
?>