Figured it out, finally. Went through many, many ways to get this working.. finally!
Cliffs: Zend Page Cache will cache HEAD requests to a page with the same cache id as a user GET request. The problem is, the HEAD
request is always going to have an empty response body.
I added some debugging code to just after $cache->start()
in my Bootstrap.php to log some details about what pages were being accessed, what protocol, host, response code, user agent and IP.
$start = $cache->start();
$start = $start === false ? 'false' : 'true';
$uri = $this->ns->https ? 'https://' : 'http://';
$uri = $uri . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$debug = date('Y-m-d H:i:s', time()) . "\t".$_SERVER['REMOTE_ADDR']."\t".$_SERVER['REQUEST_METHOD']."\tCache: $start\tUri: $uri";
$debug .= "\t " . http_response_code() . "\t";
$debug .= "\t " . $_SERVER['HTTP_USER_AGENT'];
file_put_contents(APPLICATION_PATH.'/logs/cachestartresult.log', $debug."\n", FILE_APPEND);
I added this to Zend_Cache_Frontend_Page
just before the die()
in start()
to indicate that its cached, but there's no data.
$uri = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$debug = date('Y-m-d H:i:s', time()) . "\t".$_SERVER['REMOTE_ADDR']."\t".$_SERVER['REQUEST_METHOD']."\tCache: true (dieing".(empty($data) ? " - data is but cache exists":"").")\tUri: $uri";
$debug .= "\t " . http_response_code() . "\t";
file_put_contents(APPLICATION_PATH.'/logs/cachestartresult.log', $debug."\n", FILE_APPEND);
I added this before the ob_start()
in the start()
function:
$uri = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$debug = date('Y-m-d H:i:s', time()) . "\t".$_SERVER['REMOTE_ADDR']."\t".$_SERVER['REQUEST_METHOD']."\tCache: new cache\tUri: $uri";
$debug .= "\t " . http_response_code() . "\t";
file_put_contents(APPLICATION_PATH.'/logs/cachestartresult.log', $debug."\n", FILE_APPEND);
So basically I found the output was:
I loaded a page, it cached fine. If I cleared the cache, and a HEAD request was performed before it was cached again (say, by Newrelic or pingdom etc), it would cache the page as empty and would not work again until I cleaned the cache.
Now my only concern is how the cache is emptying itself automatically. But yay! I blocked it off by only starting cache of $_SERVER['REQUEST_METHOD'] != "Head"