Ejemplo n.º 1
0
function retrieveFromIndex($query)
{
    $results = array();
    // Array of documents
    $cache = retrieveFromCache($query);
    if ($cache != null) {
        return $cache;
    } else {
        saveToCache($query, $results);
        return $results;
    }
}
Ejemplo n.º 2
0
<?php

$GLOBALS['cacheDir'] = dirname(__FILE__) . DIRECTORY_SEPARATOR . '.cache';
// 从浏览器转发过来的 proxy 请求,$_SERVER['REQUEST_URI'] 是原始的目标网址
$url = $_SERVER['REQUEST_URI'];
$req_headers = getAllHeaders();
list($resp_headers, $resp_body) = loadFromCache($url);
if (empty($resp_body)) {
    list($resp_headers, $resp_body) = doAgent(str_replace('-min.js', '.js', $url), $req_headers);
    if (empty($resp_body)) {
        list($resp_headers, $resp_body) = doAgent($url, $req_headers);
    }
    if (!empty($resp_body)) {
        saveToCache($url, $resp_headers, $resp_body);
    }
}
foreach ($resp_headers as $resp_header) {
    $tokens = explode(':', $resp_header);
    $whitelist = array('content-type', 'last-modified');
    if (in_array(strtolower($tokens[0]), $whitelist)) {
        header($resp_header);
    }
}
echo $resp_body;
function convUrlToFilename($url)
{
    $fnHead = $GLOBALS['cacheDir'] . DIRECTORY_SEPARATOR . md5($url);
    $fnBody = $fnHead . '.';
    preg_match('/^.*(\\.\\w{1,4}).*$/', $url, $matches);
    if (!empty($matches[1])) {
        $fnBody = $fnHead . $matches[1];
Ejemplo n.º 3
0
<html>
<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
</head>
<body>
  <?php 
if (!file_exists($filePath) || isset($_GET['force'])) {
    $ac = new AhoCorasick();
    $ac->setCombineResults(false);
    memUsage($memoryWhole, "Memory (AC instantiated):");
    $keywords = getKeywords();
    memUsage($memoryWhole, "Memory (keywords loaded):");
    $tree = $ac->buildTree($keywords);
    memUsage($memoryWhole, "Memory (tree built):");
    unset($keywords);
    memUsage($memoryWhole, "Memory (keywords unset):");
    saveToCache($ac, $filePath);
    memUsage($memoryWhole, "Memory (result cached):");
} else {
    $ac = unserialize(file_get_contents($filePath));
}
$res = $ac->FindAll($inputText);
memUsage($memoryWhole, "Memory (after find all):");
memUsage($memoryWhole, "Memory whole:");
unset($ac);
echo "<b>Results: </b><pre>";
var_dump($res);
echo "</pre>";
?>
</body>
</html>
Ejemplo n.º 4
0
/**
* Title
*
* Description
*
* @access public
*/
function getGlobal($varname)
{
    $tmp = explode('.', $varname);
    if (isset($tmp[2])) {
        $object_name = $tmp[0] . '.' . $tmp[1];
        $varname = $tmp[2];
    } elseif ($tmp[1]) {
        $object_name = $tmp[0];
        $varname = $tmp[1];
    } else {
        $object_name = 'ThisComputer';
    }
    $cached_name = 'MJD:' . $object_name . '.' . $varname;
    $cached_value = checkFromCache($cached_name);
    if ($cached_value !== false) {
        return $cached_value;
    }
    $obj = getObject($object_name);
    if ($obj) {
        $value = $obj->getProperty($varname);
        saveToCache($cached_name, $value);
        return $value;
    } else {
        return 0;
    }
}
Ejemplo n.º 5
0
 /**
 * Title
 *
 * Description
 *
 * @access public
 */
 function setProperty($property, $value, $no_linked = 0)
 {
     startMeasure('setProperty');
     startMeasure('setProperty (' . $property . ')');
     $id = $this->getPropertyByName($property, $this->class_id, $this->id);
     $old_value = '';
     if ($id) {
         $prop = SQLSelectOne("SELECT * FROM properties WHERE ID='" . $id . "'");
         $v = SQLSelectOne("SELECT * FROM pvalues WHERE PROPERTY_ID='" . (int) $id . "' AND OBJECT_ID='" . (int) $this->id . "'");
         $old_value = $v['VALUE'];
         $v['VALUE'] = $value;
         if ($v['ID']) {
             $v['UPDATED'] = date('Y-m-d H:i:s');
             if ($old_value != $value) {
                 SQLUpdate('pvalues', $v);
             } else {
                 SQLExec("UPDATE pvalues SET UPDATED='" . $v['UPDATED'] . "' WHERE ID='" . $v['ID'] . "'");
             }
             $cached_name = 'MJD:' . $this->object_title . '.' . $property;
             saveToCache($cached_name, $value);
         } else {
             $v['PROPERTY_ID'] = $id;
             $v['OBJECT_ID'] = $this->id;
             $v['VALUE'] = $value;
             $v['UPDATED'] = date('Y-m-d H:i:s');
             $v['ID'] = SQLInsert('pvalues', $v);
         }
         //DebMes(" $id to $value ");
     } else {
         $prop = array();
         $prop['OBJECT_ID'] = $this->id;
         $prop['TITLE'] = $property;
         $prop['ID'] = SQLInsert('properties', $prop);
         $v['PROPERTY_ID'] = $prop['ID'];
         $v['OBJECT_ID'] = $this->id;
         $v['VALUE'] = $value;
         $v['UPDATED'] = date('Y-m-d H:i:s');
         $v['ID'] = SQLInsert('pvalues', $v);
     }
     if ($this->keep_history > 0) {
         $prop['KEEP_HISTORY'] = $this->keep_history;
     }
     //if (($prop['KEEP_HISTORY']>0) && (($value!=$old_value) || (defined('KEEP_HISTORY_DUPLICATES') && KEEP_HISTORY_DUPLICATES==1))) {
     if (isset($prop['KEEP_HISTORY']) && $prop['KEEP_HISTORY'] > 0 && $value != $old_value) {
         startMeasure('DeleteOldHistory');
         SQLExec("DELETE FROM phistory WHERE VALUE_ID='" . $v['ID'] . "' AND TO_DAYS(NOW())-TO_DAYS(ADDED)>" . (int) $prop['KEEP_HISTORY']);
         endMeasure('DeleteOldHistory', 1);
         $h = array();
         $h['VALUE_ID'] = $v['ID'];
         $h['ADDED'] = date('Y-m-d H:i:s');
         $h['VALUE'] = $value;
         $h['ID'] = SQLInsert('phistory', $h);
     } elseif (isset($prop['KEEP_HISTORY']) && $prop['KEEP_HISTORY'] > 0 && $value == $old_value) {
         $tmp_history = SQLSelect("SELECT * FROM phistory WHERE VALUE_ID='" . $v['ID'] . "' ORDER BY ID DESC LIMIT 2");
         $prev_value = $tmp_history[0]['VALUE'];
         $prev_prev_value = $tmp_history[1]['VALUE'];
         if ($prev_value == $prev_prev_value) {
             $tmp_history[0]['ADDED'] = date('Y-m-d H:i:s');
             SQLUpdate('phistory', $tmp_history[0]);
         } else {
             $h = array();
             $h['VALUE_ID'] = $v['ID'];
             $h['ADDED'] = date('Y-m-d H:i:s');
             $h['VALUE'] = $value;
             $h['ID'] = SQLInsert('phistory', $h);
         }
     }
     if (isset($prop['ONCHANGE']) && $prop['ONCHANGE']) {
         global $property_linked_history;
         if (!$property_linked_history[$property][$prop['ONCHANGE']]) {
             $property_linked_history[$property][$prop['ONCHANGE']] = 1;
             global $on_change_called;
             $params = array();
             $params['PROPERTY'] = $property;
             $params['NEW_VALUE'] = (string) $value;
             $params['OLD_VALUE'] = (string) $old_value;
             $this->callMethod($prop['ONCHANGE'], $params);
             unset($property_linked_history[$property][$prop['ONCHANGE']]);
         }
     }
     if (isset($v['LINKED_MODULES']) && $v['LINKED_MODULES']) {
         // TO-DO !
         if (!is_array($no_linked) && $no_linked) {
             return;
         } elseif (!is_array($no_linked)) {
             $no_linked = array();
         }
         $tmp = explode(',', $v['LINKED_MODULES']);
         $total = count($tmp);
         for ($i = 0; $i < $total; $i++) {
             $linked_module = trim($tmp[$i]);
             if (isset($no_linked[$linked_module])) {
                 continue;
             }
             if (file_exists(DIR_MODULES . $linked_module . '/' . $linked_module . '.class.php')) {
                 include_once DIR_MODULES . $linked_module . '/' . $linked_module . '.class.php';
                 $module_object = new $linked_module();
                 if (method_exists($module_object, 'propertySetHandle')) {
                     $module_object->propertySetHandle($this->object_title, $property, $value);
                 }
             }
         }
     }
     /*
      $h=array();
      $h['ADDED']=date('Y-m-d H:i:s');
      $h['OBJECT_ID']=$this->id;
      $h['VALUE_ID']=$v['ID'];
      $h['OLD_VALUE']=$old_value;
      $h['NEW_VALUE']=$value;
      SQLInsert('history', $h);
     */
     endMeasure('setProperty (' . $property . ')', 1);
     endMeasure('setProperty', 1);
 }
Ejemplo n.º 6
0
    if (file_exists($path) && filemtime($path) > time() - $duration) {
        return file_get_contents($path);
    }
    return false;
}
//try to get it from cache
if ($cache && ($data = getFromCache($config['username'], $limit))) {
    echo $data;
    exit;
}
// Set up the oauth Authorization array
$oauth = array('oauth_consumer_key' => $config['consumer_key'], 'oauth_nonce' => time(), 'oauth_signature_method' => 'HMAC-SHA1', 'oauth_token' => $config['oauth_access_token'], 'oauth_timestamp' => time(), 'oauth_version' => '1.0');
$base_info = buildBaseString($base_url, 'GET', array_merge($oauth, $url_arguments));
$composite_key = rawurlencode($config['consumer_secret']) . '&' . rawurlencode($config['oauth_access_token_secret']);
$oauth_signature = base64_encode(hash_hmac('sha1', $base_info, $composite_key, true));
$oauth['oauth_signature'] = $oauth_signature;
// Make Requests
$header = array(buildAuthorizationHeader($oauth), 'Expect:');
$options = array(CURLOPT_HTTPHEADER => $header, CURLOPT_HEADER => false, CURLOPT_URL => $full_url, CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYPEER => false);
$feed = curl_init();
curl_setopt_array($feed, $options);
$result = curl_exec($feed);
$info = curl_getinfo($feed);
curl_close($feed);
saveToCache($result, $config['username'], $limit);
// Send suitable headers to the end user.
if (isset($info['content_type']) && isset($info['size_download'])) {
    header('Content-Type: ' . $info['content_type']);
    header('Content-Length: ' . $info['size_download']);
}
echo $result;