FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
scheduler_status.php
Go to the documentation of this file.
1 <?php
7 error_reporting(E_ALL);
8 
9 /* Allow the script to hang around waiting for connections. */
10 set_time_limit(0);
11 
12 $address = '127.0.0.1';
13 $port = 5555;
14 
15 if (($sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP)) === false)
16 {
17  echo "socket_create() failed: reason: " . socket_strerror(socket_last_error()) . "<br>\n";
18 }
19 
20 $result = socket_connect($sock, $address, $port);
21 if ($result === false)
22 {
23  echo "<h2>Connection to the scheduler failed. Is the scheduler running?</h2>";
24  echo "socket_connect() failed.\nReason: ($result) " . socket_strerror(socket_last_error($sock)) . "<br>\n";
25  exit;
26 }
27 else
28 {
29  echo "Connected to scheduler at '$address' on port '$port'...<br>";
30 }
31 
32 $msg = "status";
33 socket_write($sock, $msg, strlen($msg));
34 
35 while ($buf = socket_read($sock, 2048, PHP_NORMAL_READ))
36 {
37  if (substr($buf, 0, 3) == "end") break; // end of scheduler response
38  echo "Status is:<br>$buf<br>";
39 }
40 
41 echo "Closing socket<br>";
42 socket_close($sock);
43 ?>
int socket_connect(char *host, char *port)
Create a socket connection.
Definition: fo_cli.c:65