Example #1
0
    }
    //Else if zlib is loaded start the compression.
    if (extension_loaded('zlib') and strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== FALSE) {
        ob_start('ob_gzhandler');
    }
    return true;
}
function _compress($path)
{
    $supportsGzip = strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== false;
    if ($supportsGzip) {
        exec("gzip -c -f -1 " . $path . " > " . $path . ".gz");
        $content = file_get_contents($path . ".gz");
        //gzencode( trim( preg_replace( '/\s+/', ' ', $data ) ), 1);
    } else {
        // 		$content = $data;
        $content = file_get_contents($path);
    }
    $offset = 60 * 60;
    $expire = "expires: " . gmdate("D, d M Y H:i:s", time() + $offset) . " GMT";
    header('Content-Encoding: gzip');
    header("content-type: text/plain; charset: UTF-8");
    header("cache-control: must-revalidate");
    header($expire);
    header('Content-Length: ' . strlen($content));
    header('Vary: Accept-Encoding');
    echo $content;
}
// _compress( @file_get_contents($path) );
_compress($path);
// ob_end_flush();
Example #2
0
function cssFileCreate($queryString)
{
    global $cacheDir, $mimetype;
    $content = explode('?', urldecode($queryString));
    @($content = file_get_contents($content[0]));
    if ($content == FALSE) {
        header("content-type: text/css; charset: UTF-8");
        $content = '*{ background:red;}.body{background:red;}';
        echo $content;
        exit;
    }
    $cache = new DwcCache($cacheDir . '/css');
    $md = md5($content);
    $data = $cache->get($md);
    if ($data == FALSE) {
        $data = cssFileOptimizer($content);
        $cache->set($md, $data);
    }
    _compress($data, $mimetype['css'], $cache->getTime($md));
}