Forum Moderators: phranque
this happens only when refreshing dynamic pages
<?php
ob_start();
include('classes/class.Conteg.php');
session_start();
include_once('./config.php');
generatePage();
new Conteg();
?>
Last-Modified: Sun, 15 Aug 2010 19:39:32 GMT
Expires: Sun, 15 Aug 2010 20:39:32 GMT
Content-Encoding: gzip
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
session.cache_limiter(defaults to
nocache).
time(), which is the current date-time. If your pages are truly dynamic (capable of changing on every access) that's what you want. If your pages contain fixed-info (which may be updated later) then you need to store a last-modified date & pass that to Conteg. However, that would also be negated by the current Sessions setup.
I'm a bit worried by the lack of colons (`:') & spaces! I assume that that is your copy/paste.Yes this is my copy/paste bug.
<?php
ob_start();
session_cache_limiter ("private_no_expire, must-revalidate");
session_start();
include('classes/class.Conteg.php');
$param = array(
'use_etag' => true,
'expiry' => 84600
);
$_Instance = new Conteg( $param );
include_once('./config.php');
//here all the logic and database queries happen
//and the page output
generatePage();
$param = array(
'modified' => 1281909504
);
$_Instance->setup( $param );
$_Instance->show();
?> DateSun, 15 Aug 2010 22:40:59 GMT
ServerApache/2.2.15 (FreeBSD) mod_ssl/2.2.15 OpenSSL/0.9.8k DAV/2 PHP/5.3.2 with Suhosin-Patch
X-Powered-ByPHP/5.3.2
Last-ModifiedSun, 15 Aug 2010 21:58:24 GMT
ExpiresMon, 16 Aug 2010 22:10:59 GMT
Content-Languageen
VaryAccept-Encoding,User-Agent
EtagW/"5c4658281acbe6e136574a9aac5a168f"
Status200 OK
Content-Encodinggzip
Content-Length834
X-Content-Encoded-Byclass.Conteg.0.13.8
Content-Typetext/html; charset=ISO-8859-1 Last ModifiedMon Aug 16 2010 20:17:34 GMT+0200 (Central Europe Daylight Time)
Last FetchedMon Aug 16 2010 20:17:34 GMT+0200 (Central Europe Daylight Time)
ExpiresTue Aug 17 2010 00:10:59 GMT+0200 (Central Europe Daylight Time) if($_Instance->show()){
exit;
}
generatePage(); Conteg::show(). Clearly, that needs fixing, since it means that the whole page has to be produced before the server decides not to send any of that resource-intensive work. I'll get onto it straight away (an extra function would seem to be the obvious method - if you have some good ideas, post now).
<?php
session_cache_limiter ("cache-all");
session_start();
include('classes/class.Conteg.php');
$page_has_changed_at = 1281941681; //get timestamp of the last change from DB or file
$_Instance = new Conteg( array('noprint' => true));
$_Instance->show_and_die($page_has_changed_at);
include_once('./config.php');
//here all the logic and database queries happen
//and the page output
generatePage();
$param = array(
'modified' => $page_has_changed_at
);
$_Instance->setup( $param );
$_Instance->show();
?>
function show_and_die($page_has_changed_at){
if(isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])){
if(strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) >= $page_has_changed_at){
$this->setup(array('modified'=>$page_has_changed_at));
$this->show();
exit;
}
}
} I made small modification
_initResponse()could be multi-entry (originally designed to be called just once).
_isResponseNoContent()which returns either (304 or 406 or 412) or FALSE. If the former, then
show()&
exit(). If the latter, carry on as normal.
If I can help you somehow please let me know. (maybe for testing)
$modified = file_get_contents('modified_timestamp');
$_Instance = new Conteg();
$param = array(
'modified' => $modified,
'charset' => 'UTF-8',
'type' => 'text/html',
'use_content_lang' => TRUE,
'use_content_type' => TRUE,
'cpu_number' => 8,
'use_etag' => TRUE,
'use_accept_charset' => FALSE
);
$_Instance->setup( $param );
if( $_Instance->isResponseNoContent()) {
$_Instance->show();
exit();
}
generatePage();
$config = array(
'modified'=>$modified,
'charset' => 'UTF-8',
'type' => 'text/html',
'use_content_lang' => TRUE,
'use_content_type' => TRUE,
'cpu_number' => 8,
'use_etag' => TRUE,
'use_accept_charset' => FALSE
);
$_Instance->setup($config);
$_Instance->show();