/** * Test tracking data retrieval. * * @param $testNumbers array An array of tracking numbers to test. */ function testDataRetrieval($testNumbers) { echo ">>> Now testing retrieval of tracking data:\n\n"; $tracker = new ParcelTracker(); $numTests = count($testNumbers); $failures = 0; $successes = 0; foreach ($testNumbers as $number) { $parcel = $tracker->getDetails($number); if (!$parcel) { // Assert false echo "\tFAIL {$number}\n"; $failures++; } else { // Assert true echo "\tPASS {$number}\n"; $successes++; // DEBUG //print_r($parcel); } } echo "\nRan {$numTests} tests, {$failures} failures and {$successes} successes.\n"; }
$lastmod = gmdate('D, d M Y H:i:s \\G\\M\\T', $modtime); if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && $_SERVER['HTTP_IF_MODIFIED_SINCE'] == $lastmod) { // Cached by the browser header('Last-Modified: ' . $lastmod, true, 304); return; } // Use file-based cache header('Last-Modified: ' . $lastmod, true, 200); } else { $rss = ''; } } } if (empty($rss)) { // Perform a new tracking lookup $tracker = new ParcelTracker($config); $parcel = $tracker->getDetails($trackingNumber, $carrier); // DEBUG //print_r($parcel); //return; $rss = $tracker->toRSS($parcel, $config['cacheInterval']); if ($config['cacheInterval'] > 0) { // Cache the results file_put_contents($cacheFile, $rss); // Output last-modified header to enable browser/device caching $lastmod = gmdate('D, d M Y H:i:s \\G\\M\\T', filemtime($cacheFile)); header('Last-Modified: ' . $lastmod, true, 200); } } // Output the results header('Content-type: text/xml');