示例#1
0
 static function get($host, $object_id, $cache_ttl = null)
 {
     if ($cache_ttl) {
         $cache_var = str_replace('.', '_', $host->ip . $object_id);
         $cache = new CacheAPC();
         $resultCache = $cache->load($cache_var);
         if ($resultCache !== null) {
             return $resultCache;
         }
     }
     snmp_set_oid_output_format(self::$oid_format);
     $snmp = $host->snmpTemplate;
     if ($snmp instanceof SnmpTemplate) {
         switch ($snmp->version) {
             case "1":
                 $result = @snmpget($host->ip, $snmp->community, $object_id, $snmp->timeout, $snmp->retries);
                 break;
             case "2":
             case "2c":
                 $result = @snmp2_get($host->ip, $snmp->community, $object_id, $snmp->timeout, $snmp->retries);
                 break;
             case "3":
                 $result = @snmp3_get($host->ip, $snmp->security_name, $snmp->security_level, $snmp->auth_protocol, $snmp->auth_passphrase, $snmp->priv_protocol, $snmp->priv_passphrase, $object_id, $snmp->timeout, $snmp->retries);
                 break;
             default:
                 throw new Exception('SNMP Template not implemented yet');
         }
     }
     if ($result) {
         // retira 'STRING: ' do inicio do texto
         $result = trim(preg_replace('/^[^:]+: ?/', '', $result));
         if ($cache_var && $cache_ttl) {
             $cache->save($cache_var, $result, $cache_ttl);
         }
         return $result;
     } else {
         //throw new Exception("Sem resposta SNMP");
         return null;
     }
 }
示例#2
0
<?php

echo 'This is a test APC-Cache';
require_once 'CacheApc.php';
$data = array('name' => 'table', 'color' => 'brown', 'size' => array('x' => 200, 'y' => 120, 'z' => 150), 'strength' => 10);
$oCache = new CacheAPC();
if ($oCache->enable) {
    $oCache->setData('myTest', $data);
    echo "Data is cached, click <a href='index2.php'>here</a> to see";
} else {
    echo 'APC not intalled';
}
示例#3
0
<?php

require_once 'CacheApc.php';
$oCache = new CacheAPC();
if ($oCache->enable) {
    $cacheData = $oCache->getData('myTest');
    echo 'Data from memory: <pre>';
    print_r($cacheData);
    echo '</pre>';
    echo 'Click <a href="index3.php">here</a> to delete cache';
} else {
    echo 'APC not installed';
}
示例#4
0
文件: apc.php 项目: arout/halcyon
<?php

$oCache = new CacheAPC();
if ($oCache->bEnabled) {
    // if APC enabled
    $aMemData = $oCache->getData('my_object');
    // getting data from memory
    $aMemData2 = $oCache->getData('our_class_object');
    // getting data from memory about our class
    echo 'Data from memory: <pre>';
    // lets see what we have from memory
    print_r($aMemData);
    echo '</pre>';
    echo 'Data from memory of object of CacheAPC class: <pre>';
    print_r($aMemData2);
    echo '</pre>';
    echo 'As you can see - all data read successfully, now lets remove data from memory and check results, click <a href="index3.php">here</a> to continue';
} else {
    echo 'Seems APC not installed, please install it to perform tests';
}