// online at: // // http://www.nagios.com/legal/contributoragreement/ // // // DISCLAIMER: // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A // PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT // HOLDERS BE LIABLE FOR ANY CLAIM FOR DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, // OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE // GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, STRICT LIABILITY, TORT (INCLUDING // NEGLIGENCE OR OTHERWISE) OR OTHER ACTION, ARISING FROM, OUT OF OR IN CONNECTION // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. require_once 'cache_or_disk.php'; if (useAPC() && (FALSE || isset($_GET['CLEANCACHE']))) { // For Debugging data from disk apc_clear_cache(); apc_clear_cache('user'); } require_once 'data_utils.php'; require_once 'NagiosData.php'; require_once 'NagiosUser.php'; require_once 'get_tac_data.php'; require_once 'build_groups.php'; require_once 'read_objects.php'; require_once 'read_status.php'; require_once 'read_perms.php'; require_once 'process_details.php';
function cache_or_disk($keyword, $backing_file, $cache_keys) { // fb("cache_or_disk({$keyword}, {$backing_file}, ..."); // fb($cache_keys, "cache_keys"); $known_keywords = array('objects', 'status', 'perms'); if (!in_array($keyword, $known_keywords)) { // XXX do something better die("Unknown keyword '{$keyword}'"); } $useAPC = useAPC(); $start_time = microtime(TRUE); $array = NULL; //fb($keyword, "doing cache_or_disk($keyword)"); if ($useAPC) { //fb(apc_cache_info(), "apc cache info"); $read_file = cache_needs_update($keyword, $backing_file); $cacheFail = FALSE; $success = FALSE; if (!$read_file) { // Loop through each variables cached value. If a read fails note it and // read from disk foreach ($cache_keys as $key) { $array[$key] = apc_fetch($key, $success); if (!$success) { $cacheFail = TRUE; //fb("Cache Fail for key {$key}!"); break; } } if (!$cacheFail) { // Every key was found in cache //fb("$keyword data from cache!"); } } } // The cache is not enabled or // the cache is enabled and of the following three conditions occurred // There was a cache miss // The data file is newer than the cached version if (!$useAPC || !$success || $read_file || $cacheFail) { $array = read_disk($keyword, $cache_keys); if ($useAPC) { //foreach($cache_keys as $key) { foreach (array_keys($array) as $key) { apc_store($key, $array[$key]); } apc_store('last_' . $keyword . '_read', time()); //fb('stored keys to cache'); } //fb("$keyword data from disk!"); } $end_time = microtime(TRUE); //fb($end_time - $start_time, "Elapsed load time {$end_time} - {$start_time}"); return $array; }