О компании Менеджмент Переводы Программирование Робототехника Все проекты Контакты
Админка
пожалуйста подождите
Долго мучился с настройкой кеширования. Оказалось, что глюк на глюке сидел и глюком погонял. Один из глюков - FireDebug. IE View показывала другие заголовки запросов, гораздо более похожие на те, что должны были быть... Итак:

Функция для формирования заголовка запроса



// Forms the HTTP-header with the response string (200 OK, 302 Redirect, etc.)
// The expiration time of the current document (could be calculated as counted in seconds
// and plus to the current time), if this value is false or 0, the caching will be disabled,
// if it is false, the expiration field woun't be set
// The time of the last modification of the data should be set either. This value is ignored
// if it is equal to false, also this value will be ignored, if the expiration time is false or 0
// (the caching is turned off).
// If this data should be stored on the user's browser cache only, the isPublic should be
// set to FALSE, and if the proxies caching is allowed, it could be set to TRUE;
// this value will be ignored for disabled caching mode.
// The content type is the MIME-type of the content (iif it is set to "", the content-type
// field woun't be changed) and the charset is it's encoding, if it is set to "", the
// DEFAULT_XML_FILES_ENCODING constant value will be used for the encoding of the
// content. If the contentType is "", the charset value is ignored either.
function buildHeader( $response, $expirationTime, $lastModificationTime, $isPublic, $contentType, $charset )
{
header( "HTTP/1.1: $response" );
header( "Status: $response" );

if ( $expirationTime !== false )
header( "Expires: " . gmdate( "D, d M Y H:i:s", $expirationTime ) . " GMT" );
if ( $expirationTime != 0 && $lastModificationTime !== false )
header( "Last-Modified: " . gmdate( "D, d M Y H:i:s", $lastModificationTime ) . " GMT" );

if ( $expirationTime == 0 )
{
header( "Cache-Control: no-cache, no-store, must-revalidate" );
header( "Pragma: no-cache" );
}
else
{
if ( $isPublic )
header( "Cache-Control: public" );
else
header( "Cache-Control: private" );
};

if ( $charset == "" )
$charset = DEFAULT_XML_FILES_ENCODING;

if ( $contentType != "" )
header( "Content-Type: ".strtolower( $contentType."; charset=".$charset ) );
}


Использование этой функции для организации кеширования RSS-файла



require_once SCRIPTS_PATH."buildHeader.php";
// retreaving the RSS file name
$rssFileName = getDocumentRssFileName( $DOCUMENT_PATH, $LANGUAGE );

// sending the file's content
$lastModificationTime = $CURRENT_TIME;
if ( file_exists( $rssFileName ) )
{
$lastModificationTime = filemtime( $rssFileName );
if ( !$lastModificationTime )
$lastModificationTime = $CURRENT_TIME;

// responsing, whether this data is not modified since the time, requested
// to free-up the server
if ( $MODIFIED_SINCE_TIME >= $lastModificationTime )
{
buildHeader( "304 Not Modified", $CURRENT_TIME CACHING_TIME_RSS, $lastModificationTime, false, "application/xml", "" );
exit();
};
}
else
reportError( RESPONSE_RSS_NOT_FOUND );

// this function is not to be cached and could not be interrupted
// starting buffering the output

// performing the authorization
require_once SCRIPTS_PATH."authorization.php";

if ( $USER_RIGHTS_READ )
{
// sending the file's content
$file = fopen( $rssFileName, "rb" );
if ( !empty( $file ) )
{
// forming the right status in the header, because of
// the server configuration, that sends all the requests to the
// main index.php, so almost all the requests have 404 status
buildHeader( "200 OK", $CURRENT_TIME CACHING_TIME_RSS, $lastModificationTime, false, "application/xml", "" );

while ( !feof( $file ) )
echo fread( $file, DATA_PART_LENGTH );
fclose( $file );
}
else
reportError( RESPONSE_RSS_NOT_FOUND );

}
else
reportError( RESPONSE_FORBIDDEN );
 
 
 
Языки
Темы
Copyright © 1999 — 2023
Зетка Интерактив