Hi,
I have spent that past 3 days trying to get this to work and finding out why it isn’t. I have a “for” loop that starts out at ‘1000’ and goes to ‘1005’ and incriments by ‘1’. Inside the loop is a script that open a text file that has several lines of text. The text is tab-delimited. Here is the code.
[code=php]<?php
$final_output = “”;
$runs = “1”;
for( $node = “1000”; $node <= “1005”; $node += “1”){
echo “start run ” . $runs . “<br>”;
echo “node: ” . $node . “<br>”;
// Opens the file and serches for the requested node number
$handle = fopen(‘localstatus.txt’ , “r”) or die(“Can’t open file….”);
while(!feof($handle)){
$buffer = fgets($handle, 4096);
$pos = strpos($buffer, $node);
if ($pos !== FALSE && $pos == ‘0’){break;}
}
echo “Buffer: ” . $buffer . “<br>”;
// Closes the file
fclose($handle);
// Sorts the gathered data
$buf_arr = explode(“t”, $buffer);
echo “Buf_arr: ” . $buf_arr . ” arr <br>”;
// Assigns the status of the node to a string
$status = $buf_arr[‘5’];
if($status == ‘Busy’) {
$status = ‘BUSY’;
}
// Assigns the node callsign to a string
$callsign = $buf_arr[‘1’];
// Assembles first part of output
$own_node = ($callsign . ‘ Node ‘ . $node);
// Based on what the status was, the finnal output and color ar being set
switch ($status) {
case ‘BUSY’:
$node_status = $own_node . ‘ is ‘ . $status;
$color = ‘#FF0000’;
break;
case ‘OFFLINE’:
$node_status = $own_node . ‘ is ‘ . $status;
$color = ‘#FF0000’;
break;
case ‘DOWN’:
$node_status = $own_node . ‘ is ‘ . $status;
$color = ‘#FF0000’;
break;
case ‘IDLE’:
$node_status = ($own_node . ‘ is ‘ . $status);
$color = ‘#00FF00’;
break;
default:
if ($status <= ‘8999’) {
$node_status = $own_node . ‘ is connected to Node ‘ . $status;
$color = ‘#FF0000’;
}
elseif ($status >= ‘9000’) {
$node_status = $own_node . ‘ is connected to Reflecter ‘ . $status;
$color = ‘#FFFF00’;
}
break;
}
// Verifies the node number proccessed is the same node that was requested
$verify = $buf_arr[‘0’];
if ($verify !== $node) {
$node_status = ‘Sorry, there was no data found for Node ‘ . $node;
$color = ‘#33CCFF’;
}
$final_output .= “<font color=$color>”;
$final_output .= “$node_status”;
$final_output .= “</font><br>”;
echo “end <br><br>”;
$runs ++;
}
echo “<center><b>IRLP Node Status Script</B><br><br>”;
// Displays your nodes to you page
echo $final_output;
?>
The problem I am having is the first time through it works fine but every time after that ‘$buffer’ is always empty. This is the output to the browser.
[CODE]start run 1
node: 1000
Buffer: 1000 VE7RHS Vancouver BC Canada IDLE 1000 1998-11-12 49.269892 -123.25002 1178224118 145.2700 -600.0000 100.0 ve7ltd http://www.ars.ams.ubc.ca 1178221826 O
Buf_arr: Array arr
end
start run 2
node: 1001
Buffer:
Buf_arr: Array arr
Notice: Undefined index: 5 in E:Program FilesApache GroupApache2htdocsAAINan.php on line 24
Notice: Undefined index: 1 in E:Program FilesApache GroupApache2htdocsAAINan.php on line 30
end
start run 3
node: 1002
Buffer:
Buf_arr: Array arr
Notice: Undefined index: 5 in E:Program FilesApache GroupApache2htdocsAAINan.php on line 24
Notice: Undefined index: 1 in E:Program FilesApache GroupApache2htdocsAAINan.php on line 30
end
start run 4
node: 1003
Buffer:
Buf_arr: Array arr
Notice: Undefined index: 5 in E:Program FilesApache GroupApache2htdocsAAINan.php on line 24
Notice: Undefined index: 1 in E:Program FilesApache GroupApache2htdocsAAINan.php on line 30
end
start run 5
node: 1004
Buffer:
Buf_arr: Array arr
Notice: Undefined index: 5 in E:Program FilesApache GroupApache2htdocsAAINan.php on line 24
Notice: Undefined index: 1 in E:Program FilesApache GroupApache2htdocsAAINan.php on line 30
end
start run 6
node: 1005
Buffer:
Buf_arr: Array arr
Notice: Undefined index: 5 in E:Program FilesApache GroupApache2htdocsAAINan.php on line 24
Notice: Undefined index: 1 in E:Program FilesApache GroupApache2htdocsAAINan.php on line 30
end
IRLP Node Status Script
VE7RHS Node 1000 is IDLE
Sorry, there was no data found for Node 1001
Sorry, there was no data found for Node 1002
Sorry, there was no data found for Node 1003
Sorry, there was no data found for Node 1004
Sorry, there was no data found for Node 1005
Does anyone know why this isn’t working or what I am doing wrong?