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