function ServerReportingTest($url, $id, &$sql) { echo "Testing server reporting...\n"; $resp = SimpleHEAD::HEADrequest($url); $useslm = 0; $usesetag = 0; if (!isset($resp['lm']) || empty($resp['lm'])) { echo "The bloody server doesn't report Last-Modified info.\n"; $useslm = false; } else { echo "Aw yeah, it supports Last-Modified.\n"; if (!ServerTestPackage::LMReliabilityTest($url)) { echo "Last-Modified timestamps are unreliable!\n"; $useslm = false; } else { echo "Last-Modified timestamps are reliable.\n"; $useslm = true; } } if (!isset($resp['et']) || empty($resp['et'])) { echo "The bloody server doesn't report ETag info.\n"; $usesetag = false; } else { echo "Aw yeah, it supports ETag.\n"; $usesetag = true; } echo "Storing these details in the database..."; if ($usesetag === true && $useslm === true) { // supports both etag and last-modified $sql->write('feeds', array('reports' => 'complete', 'etag' => $resp['et'], 'lastmodified' => date('Y-m-d H:i:s', strtotime($resp['lm']))), $id); } elseif ($usesetag === true && $useslm === false) { // supports only etag (I don't expect this to happen) $sql->write('feeds', array('reports' => 'etagonly', 'etag' => $resp['et']), $id); } elseif ($usesetag === false && $useslm === true) { // supports only last-modified $sql->write('feeds', array('reports' => 'lmonly', 'lastmodified' => date('Y-m-d H:i:s', strtotime($resp['lm']))), $id); } elseif ($usesetag === false && $useslm === false) { // supports neither etag nor last-modified (bad server!) $sql->write('feeds', array('reports' => 'none'), $id); } else { // ambiguous test results die("Ambiguous test results: useslm = {$useslm}, usesetag = {$usesetag}.\n"); } echo "Done.\n"; }