Example #1
0
function utiliser_cache($url)
{
    $md5 = md5($url);
    $h = trouver_cache(DIRCACHE . $md5);
    if ($h and !limiter_cache($h)) {
        actualiser_cache($md5);
        foreach ($h as $l) {
            header($l);
        }
        readfile(DIRCACHE . $md5 . "." . typer_cache($h));
    } elseif (!preg_match(RE_URL, $url, $m)) {
        header('HTTP/1.1 400');
        echo "URL incomprise";
    } else {
        list($entetes, $page) = alimenter_cache($m[1], $m[4], $m[3] ? $m[3] : 80);
        if (!$entetes) {
            header('HTTP/1.1 400');
            echo "Serveur injoignable";
        } else {
            if (necessiter_cache($entetes) and memoriser_cache(DIRCACHE . $md5, $entetes, $page)) {
                // En PHP, pour une condition avec AND le second argument n'est pas tester si le premier est faux
                actualiser_cache($md5);
            }
        }
    }
}
Example #2
0
function trouver_cache($nom)
{
    if (!is_readable($nom . '.http')) {
        return array();
    }
    $h = file($nom . '.http');
    $type = typer_cache($h);
    return is_readable($nom . '.' . $type) ? $h : array();
}
Example #3
0
function nettoie_cache($tabCaches)
{
    sort($tabCaches);
    $nom = key($tabCaches);
    $nom_h = $nom . '.http';
    $nom_t = $nom . '.' . typer_cache(file($nom_h));
    unlink($nom_h);
    unlink($nom_t);
    array_shift($tabCaches);
    return $tabCaches;
}
Example #4
0
function memoriser_cache($nom, $entetes, $page)
{
    $type = typer_cache($entetes);
    if ($d1 = fopen($nom . ".http", 'w') and $d2 = fopen($nom . "." . $type, 'w')) {
        fputs($d1, join('', $entetes));
        fclose($d1);
        fputs($d2, $page);
        fclose($d2);
        return true;
    }
    return false;
}