Пример #1
0
function jpcache_end($contents)
{
    global $pretext;
    jpcache_debug("Callback happened");
    // We do a binary comparison of the first two bytes, see
    // rfc1952, to check wether the content is gzipped.
    $is_gzipped = strncmp($contents, "‹", 2) === 0;
    // If the connection was aborted, do not write the cache.
    // We don't know if the data we have is valid, as the user
    // has interupted the generation of the page.
    // Also check if jpcache is not disabled
    // Also skip if content is less then 50 bytes (uncompressed) or 17 Bytes (comrpessed)
    if (connection_aborted() || $GLOBALS["JPCACHE_ON"] == 0 || $GLOBALS["JPCACHE_TIME"] <= 0 || strlen($contents) / (1 + $is_gzipped * 2) < 50 || $pretext['status'] != 200) {
        jpcache_debug("Skipped writing Cachefile. Returned as is.");
        return $contents;
    }
    // If it's compressed in the script, decompress first.
    if ($is_gzipped) {
        $contents = gzinflate(substr($contents, 10));
    }
    $contents_snippet = substr($contents, 0, 50);
    $gzdata = $GLOBALS["JPCACHE_USE_GZIP"] ? gzcompress($contents, $GLOBALS["JPCACHE_GZIP_LEVEL"]) : $contents;
    $datasize = strlen($contents);
    $datacrc = crc32($contents);
    jpcache_debug("Writing cached data to storage");
    // write the cache with the current data
    jpcache_write($gzdata, $datasize, $datacrc, $contents_snippet);
    // Handle type-specific additional code if required
    jpcache_do_end();
    // Return flushed data
    return jpcache_flush($gzdata, $datasize, $datacrc);
}
Пример #2
0
function jpcache_end($contents)
{
    jpcache_debug("Callback happened");
    $datasize = strlen($contents);
    $datacrc = crc32($contents);
    if ($GLOBALS["JPCACHE_USE_GZIP"]) {
        $gzdata = gzcompress($contents, $GLOBALS["JPCACHE_GZIP_LEVEL"]);
    } else {
        $gzdata = $contents;
    }
    // If the connection was aborted, do not write the cache.
    // We don't know if the data we have is valid, as the user
    // has interupted the generation of the page.
    // Also check if jpcache is not disabled
    if (!connection_aborted() && $GLOBALS["JPCACHE_ON"] && $GLOBALS["JPCACHE_TIME"] >= 0) {
        jpcache_debug("Writing cached data to storage");
        // write the cache with the current data
        jpcache_write($gzdata, $datasize, $datacrc);
    }
    // Handle type-specific additional code if required
    jpcache_do_end();
    // Return flushed data
    return jpcache_flush($gzdata, $datasize, $datacrc);
}