0 && is_int($offset)) { $check_urls = array_slice(array_reverse($check_urls), $offset, $limit); } foreach ( $check_urls as $url ) { $status = url_checker_test_url($url); $results[] = array( 'url' => $url, 'status' => $status ); if ($status != 200) { $failed++; } } $tested = sizeof($results); $output = url_checker_build_output($results, $failed); $time_end = microtime(true); print $output; print 'Tested: ' . $tested . "\n"; print 'Time: ' . ($time_end - $time_start) . " seconds\n\n"; if (isset($config['email'])) { $subject = 'Cache warm report: www.asapp.com'; $message = ''; $message .= 'Failed: ' . $failed . "\n"; $message .= 'Tested: ' . $tested . "\n"; $message .= 'Time: ' . ($time_end - $time_start) . " seconds\n\n"; $message .= "Below is a list of each tested url and its status:\n\n"; $message .= $output; $acceptedForDelivery = mail($config['email'], $subject, $message); if ($acceptedForDelivery) { print "Sent email to {$config['email']}.\n"; } else { print "Notification email to {$config['email']} could not be queued for delivery.\n"; } } } /** * Gets a list of urls from a provided sitemap address */ function get_url_list($sitemap_url) { $check_urls = array(); $xml = simplexml_load_file($sitemap_url); foreach ($xml->url as $entry) { $check_urls[] = $entry->loc; } return $check_urls; } /** * Constructs workflow output */ function url_checker_build_output($results, $failed) { $output = "\nURL Checks\n--------\n"; foreach ($results as $item) { $output .= ' ' . $item['status'] . ' - ' . $item['url'] . "\n"; } $output .= "--------\n" . $failed . " failed\n\n"; return $output; } /** * Try to access the specified URL, and return the http status code. */ function url_checker_test_url($url) { $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_exec($ch); $info = curl_getinfo($ch); curl_close($ch); return $info['http_code']; } ?>