"Fossies" - the Fresh Open Source Software Archive 
Member "node-runner-0.6.0/contribs/query_template.php" (7 Sep 2004, 2050 Bytes) of package /linux/www/old/node-runner-0.6.0.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
For more information about "query_template.php" see the
Fossies "Dox" file reference documentation.
1 <?php
2
3 /*
4 If you're reading this, Node Runner probably doesn't do quite everything you
5 hoped it would do. This is a template for building your own custom network
6 queries. The lines below are those necessary to return appropriate data and
7 functionality to the Node Runner polling script. I have commented each line
8 for a better explanation. If you come up with a custom query that others may
9 find useful, please email it to me and I will evaluate it for future versions.
10 If you have little experience with php, networking, or sockets in general, it's
11 probably a good idea to do some reading before attempting to make your own
12 custom queries.
13 */
14
15
16 /*
17 The following line identifies the query type in the database for each node.
18 The description here can be anything, and will show up as a possible query
19 type in the web interface.
20 */
21 array_push($queries_type_array, "TCP");
22
23
24
25 /*
26 Now we set up our function, which will need to be added to the node.start script
27 after you have created it (see function "query_socket" in node.start).
28 */
29 function tcp_query($description, $ipaddress, $port, $ptime) {
30 global $debug; // include this line for debugging
31
32 $status = array(); // this function should return an array (see end of function).
33
34 $socket = fsockopen($ipaddress, $port, $errno, $errstr, $ptime);
35
36 if (!$socket) {
37 $status[0] = 0; // The value of the first element of the array should either
38 // be 0 for unresponsive nodes, 1 for responsive nodes.
39
40 $status[1] = $description." DOWN"; // The value of the second element of the
41 // array serves as the status message you
42 // wish to receive. Same with the level
43 // of debugging that you can add (below).
44
45 if ($debug == 1) { $status[1] .= " - TCP Error ".$errno.": ".$errstr; }
46 } else {
47 $status[0] = 1;
48 $status[1] = $description." UP";
49 if ($debug == 1) { $status[1] .= " - TCP Port ".$port." Responded Correctly."; }
50 }
51
52 if ($socket) { fclose($socket); }
53
54 $status[1] .= "\n";
55 return $status;
56
57 }
58
59 ?>