Ejemplo n.º 1
1
 * memcached
 */
if (MEMCACHED) {
    $perma = parse_url($_SERVER['REQUEST_URI']);
    $_PERMA = explode("/", $perma['path']);
    @array_shift($_PERMA);
    if (isset($_PERMA[0]) && $_PERMA[0] != basename($_SERVER['PHP_SELF'])) {
        include 'db/library/pca/pca.class.php';
        $cache = PCA::get_best_backend();
        if ($cache->exists($_SERVER['REQUEST_URI'])) {
            header('Location: ' . $cache->get($_SERVER['REQUEST_URI']), TRUE, 301);
            exit;
        }
    }
    include 'db/library/pca/pca.class.php';
    $cache = PCA::get_best_backend();
    $_SERVER['FULL_URL'] = 'http://';
    if ($_SERVER['SERVER_PORT'] != '80') {
        $port = ':' . $_SERVER['SERVER_PORT'];
    }
    if (isset($_SERVER['REQUEST_URI'])) {
        $script = $_SERVER['REQUEST_URI'];
    } else {
        $script = $_SERVER['PHP_SELF'];
        if ($_SERVER['QUERY_STRING'] > ' ') {
            $script .= '?' . $_SERVER['QUERY_STRING'];
        }
    }
    if (isset($_SERVER['HTTP_HOST'])) {
        $_SERVER['FULL_URL'] .= $_SERVER['HTTP_HOST'] . $port . $script;
    } else {
Ejemplo n.º 2
0
function read_cache_blob(&$request, $value, $coll)
{
    if (isset($coll[$request->resource])) {
        if ($coll[$request->resource]['duration'] > 0) {
            $cacheFile = $coll[$request->resource]['location'] . DIRECTORY_SEPARATOR . $request->resource . $request->id;
            if (!is_dir($coll[$request->resource]['location'] . DIRECTORY_SEPARATOR)) {
                return;
            }
            if (file_exists($cacheFile) && filemtime($cacheFile) > time() - $coll[$request->resource]['duration']) {
                // read cacheFile
                if (!($fp = fopen($coll[$request->resource]['location'] . DIRECTORY_SEPARATOR . 'hits', 'a'))) {
                    trigger_error('Error opening hits file', E_USER_ERROR);
                }
                if (!flock($fp, LOCK_EX)) {
                    trigger_error('Unable to lock hits file', E_USER_ERROR);
                }
                if (!fwrite($fp, time_of(timestamp()) . " hit " . $cacheFile . "\n")) {
                    trigger_error('Error writing to cache file', E_USER_ERROR);
                }
                flock($fp, LOCK_UN);
                fclose($fp);
                unset($fp);
                if (defined('MEMCACHED') && MEMCACHED) {
                    global $response;
                    $timeout = MEMCACHED;
                    $cache = PCA::get_best_backend();
                    $cache->add($request->composite_uri(), file_get_contents($cacheFile), $timeout);
                    $cache->add($request->composite_uri() . 'type', type_of($response->pick_template_extension($request)), $timeout);
                }
                print file_get_contents($cacheFile);
                exit;
            } else {
                // write cacheFile
                if (!($fp = fopen($coll[$request->resource]['location'] . DIRECTORY_SEPARATOR . 'hits', 'a'))) {
                    trigger_error('Error opening hits file', E_USER_ERROR);
                }
                if (!flock($fp, LOCK_EX)) {
                    trigger_error('Unable to lock hits file', E_USER_ERROR);
                }
                if (!fwrite($fp, time_of(timestamp()) . " " . 'write ' . $cacheFile . "\n")) {
                    trigger_error('Error writing to cache file', E_USER_ERROR);
                }
                flock($fp, LOCK_UN);
                fclose($fp);
                unset($fp);
                if (!($fp = fopen($cacheFile, 'w'))) {
                    trigger_error('Error opening cache file', E_USER_ERROR);
                }
                if (!flock($fp, LOCK_EX)) {
                    trigger_error('Unable to lock cache file', E_USER_ERROR);
                }
                if (!fwrite($fp, fetch_blob($value, true))) {
                    trigger_error('Error writing to cache file', E_USER_ERROR);
                }
                flock($fp, LOCK_UN);
                fclose($fp);
                unset($fp);
                return;
            }
        }
    }
}
Ejemplo n.º 3
0
function do_shorten_redirect(&$model, &$model)
{
    global $request;
    if (!($model->table == 'settings')) {
        return;
    }
    $perma = parse_url($_SERVER['REQUEST_URI']);
    $_PERMA = explode("/", $perma['path']);
    @array_shift($_PERMA);
    if (isset($_PERMA[0])) {
        $id = mysql_escape_string($_PERMA[0]);
    } else {
        $id = '';
    }
    if ($id != '' && $id != basename($_SERVER['PHP_SELF'])) {
        add_include_path(library_path() . 'urlshort/upload');
        require_once 'includes/config.php';
        // settings
        require_once 'includes/gen.php';
        // url generation and location
        $url = new shorturl();
        $location = $url->get_url($id);
        if ($location != -1) {
            include 'db/library/pca/pca.class.php';
            $cache = PCA::get_best_backend();
            $timeout = 86400;
            $cache->add($_SERVER['REQUEST_URI'], $location, $timeout);
            header('Location: ' . $location, TRUE, 301);
            exit;
        }
    }
}