⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 waitforstatus.php

📁 Linux嵌入式设计配套光盘,学习嵌入式设计可参考
💻 PHP
字号:
<?php// This function connects to the logger and gets the 'count'// field from the NetDest table.  The count is used as an// ID or signature to identify the most recent log message// available.function get_log_count() {  // Suppress Postgres error messages  error_reporting(error_reporting() & 0xFFFD);  // connect to the RTA interface on the logger  $connection = pg_connect("localhost", "8887", "bsmith");  if ($connection == "") {     return(-1);  }  // Get the count of log messages so far.  This count is the "ID".  $command = "SELECT count FROM NetDest WHERE destname = 'default'";  $result = pg_exec($connection, $command);  if ($result == "") {     pg_close($connection);    return(-2);  }  $nrow = pg_NumRows($result);  if ($nrow == 1) {    $log_id = pg_result($result, 0, 0);    return($log_id);  }  else {    return(-3);  }  pg_freeresult($result);  pg_close($connection);}// This program gets the 'ID' of what is currently being// displayed on the browser window from the POST data.  If// what is currently being displayed corresponds to the most// recent events (logs), then it opens a connection to the// logger and wait for another event.  If what is displayed// is not the most recent event, then it returns immediately// with the latest Laddie status and logs.//    Change the argument in stream_set_timeout() to change// the periodic automatic update rate.    $disp_id = htmlentities($_GET[disp_id]);  $curr_id = get_log_count();  if ($disp_id == $curr_id) {    $fp = fsockopen("localhost", 4444, $errno, $errstr, 30);    if ($fp) {      stream_set_timeout($fp, 60);      $ignore_response = fgets($fp, 128);      fclose($fp);    }    $curr_id = get_log_count();  }  header("Content-Type: text/xml");  print("<?xml version=\"1.0\" ?>\n");  print("<laddie_status>\n");  // Suppress Postgres error messages  error_reporting(error_reporting() & 0xFFFD);  // connect to the database   $connection = pg_connect("localhost", "8888", "bsmith");  if ($connection == "") {     // Still need to determine best error message to send ......    exit();  }  // Get and formst status for all zones  $command = "SELECT id, name, enabled, alarm FROM Zone";  $result = pg_exec($connection, $command);  if ($result == "") {     // Still need to determine best error message to send ......    exit();  }  for($row = 0; $row < pg_NumRows($result); $row++)  {    $id    = pg_result($result, $row, 0);    $name  = pg_result($result, $row, 1);    $enabled = pg_result($result, $row, 2);    $alarm   = pg_result($result, $row, 3);    printf("<zone id=\"%s\" name=\"%s\" enabled=\"%s\">", $id, $name, $enabled);    printf("%s</zone>\n", $alarm);  }  // free the result for the status, close conn to Ladd  pg_freeresult($result);  pg_close($connection);  // Give current log count  printf("<logcount>%d</logcount>\n", $curr_id);  // connect to the RTA interface on the logger  $connection = pg_connect("localhost", "8887", "bsmith");  if ($connection == "") {     // Still need to determine best error message to send ......    exit();  }  // Get and display the most recent log messages  $command = "SELECT log FROM TblDest LIMIT 5";  $result = pg_exec($connection, $command);  if ($result == "") {     // Still need to determine best error message to send ......    pg_close($connection);    exit();  }  // print each log message as a <log>  $nrow = pg_NumRows($result);  for($row = 0; $row < $nrow; $row++)  {    $log   = pg_result($result, $row, 0);    print("<log>$log</log>\n");  }  // free the result for the log display  pg_freeresult($result);  pg_close($connection);  print("</laddie_status>\n");?>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -