--- lighttpd_stats_1.0/ss_lighttpd_stats.php 2008-10-05 17:59:04.134098093 +0300 +++ lighttpd_stats_1.0/ss_lighttpd_stats.php 2008-10-05 18:07:11.707053483 +0300 @@ -1,3 +1,4 @@ +#!/usr/bin/php // // As a script server object: -// ss_lighttpd_stats.php ss_apache_stats +// ss_lighttpd_stats.php ss_lighttpd_stats // // @@ -21,9 +22,6 @@ // // -/* display no errors */ -error_reporting(0); - if (!isset($called_by_script_server)) { include_once(dirname(__FILE__) . "/../include/config.php"); array_shift($_SERVER["argv"]); @@ -47,8 +45,8 @@ $status = lighttpdStatus::getStatus($host); $return = ''; - foreach($variables as $status_var => $cacti_var){ - if(isset($status[$status_var])){ + foreach ($variables as $status_var => $cacti_var){ + if (isset($status[$status_var])) { $return .= sprintf('%s:%s ', $cacti_var, $status[$status_var]); } } @@ -84,7 +82,7 @@ throw new Exception('Host not found'); } - $fh = @fsockopen($address, 80, $errno, $errstr, self::QUERY_TIMEOUT); + $fh = fsockopen($address, 80, $errno, $errstr, self::QUERY_TIMEOUT); if(!$fh || !is_resource($fh)){ throw new Exception($errstr, $errno); @@ -112,20 +110,24 @@ throw new Exception(''); } - $lines = explode("\n", $status); + list($headers, $body) = explode("\r\n\r\n", $status); + $headers = explode("\r\n", $headers); // check response code // should be "HTTP/1.1 200 OK" - if(trim($lines[0]) != 'HTTP/1.1 200 OK'){ - throw new Exception($lines[0]); + // can be also "HTTP/1.0 200 OK" if routed via proxy + $http_status = trim($headers[0]); + if ($http_status != 'HTTP/1.0 200 OK' && $http_status != 'HTTP/1.1 200 OK'){ + throw new Exception($http_status); } $vars = array(); - foreach($lines as $line){ + $body = explode("\n", $body); + foreach($body as $line){ $line = trim($line); - if(preg_match('/(.+): (.+)/', $line, $matches)){ + if (preg_match('/^(.+): (.+)/', $line, $matches)){ $vars[$matches[1]] = intval($matches[2]); } } @@ -140,2 +141,0 @@ - -?>