"Fossies" - the Fresh Open Source Software Archive

Member "node-runner-0.6.0/include/query_http.php" (21 Oct 2004, 2116 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_http.php" see the Fossies "Dox" file reference documentation.

    1 <?php
    2 
    3 // This is an example script that queries the HTTP service on a given node.
    4 
    5 array_push($queries_type_array, "HTTP");
    6 
    7 function http_query($description, $ipaddress, $port, $url, $username, $pass, $ptime) {
    8     GLOBAL $debug,$allow_refused;
    9     
   10     $socket = fsockopen($ipaddress, $port, $errno, $errstr, $ptime);
   11     $status = array();
   12     
   13     // If 'connection refused (111)' was received by socket, the web server must be down or blocked by firewall.
   14     if (($socket == 111) || (!$socket)) {
   15         $status[0] = 0;
   16         $status[1] = $description." DOWN";
   17         if ($debug == 1) { $status[1] .= " - HTTP Error Code ".$errno.": ".$errstr; }
   18     } else { // else connection responded, so here we go...
   19 
   20       $start_time = mktime();
   21 
   22       unset($authmsg);
   23       if ($username && $pass) {
   24          $str = "$username:$pass";
   25          $b64response = base64_encode($str);
   26          $authmsg = "Authorization: Basic $b64response\r\n";
   27       }
   28 
   29       if ($url == "/") { $url = ""; }
   30 
   31       $msg = "GET /". $url ." HTTP/1.0\r\nHost: $ipaddress\r\n$authmsg\r\n";
   32       fputs($socket,$msg);
   33 
   34       // Get HTML status codes
   35       $response = fread($socket,32);
   36       $lines = explode("\n", $response);
   37       $code_out = chop($lines[0]);
   38       $code_out = substr($code_out, 9, 3);
   39       unset($debug_status);
   40       if ($debug == 1) { $debug_status = "\nHTML Code: $code_out"; }
   41 
   42       // Array of acceptable HTML error codes
   43       $ok_array = array(200, 302, 401);
   44 
   45       if (in_array($code_out, $ok_array)) {
   46       // Web server must be responding, so check page load times
   47           $status[0] = 1;
   48           $status[1] = $description." UP".$debug_status;
   49           while (!feof($socket)) {
   50               $data = fgets ($socket,128);
   51               $mid_time = mktime();
   52             if (($mid_time - $start_time) > $ptime) {
   53                     $status[0] = 0;
   54                     $status[1] = $description." UNRESPONSIVE - HTTP Page Load > ".$ptime." Seconds";
   55                     break;
   56                 }
   57           }
   58       
   59       }
   60       
   61     }
   62     if ($socket) { fclose($socket); }
   63     $status[1] .= "\n";
   64     return $status;
   65 }
   66 
   67 ?>