function linkchecker_cron in Link checker 5.2
Same name and namespace in other branches
- 8 linkchecker.module \linkchecker_cron()
- 5 linkchecker.module \linkchecker_cron()
- 6.2 linkchecker.module \linkchecker_cron()
- 7 linkchecker.module \linkchecker_cron()
Implementation of hook_cron().
File
- ./
linkchecker.module, line 677 - This module periodically check links in given node types, blocks, cck fields, etc.
Code
function linkchecker_cron() {
// Get max_execution_time from configuration, override 0 with 240 seconds.
$max_execution_time = ini_get('max_execution_time') == 0 ? 240 : ini_get('max_execution_time');
// Remove outdated links no longer in use once per day.
if (time() - variable_get('linkchecker_cleanup_links_last', 0) >= 86400) {
_linkchecker_cleanup_links();
variable_set('linkchecker_cleanup_links_last', time());
}
// TODO: Implement cURL support.
//$has_curl = function_exists('curl_init');
// TODO: Remove some confusion about the max links that can be checked per
// cron run and guess that 2 link can be checked per second what is
// nevertheless uncommon. But we can use the max_execution_time to calculate
// a value that is higher, but not totally out of scope to keep the query
// resultset small. For cURL we need to add this setting back or a thread
// limit per remote server for not overloading them.
$check_links_max_per_cron_run = $max_execution_time;
//$check_links_max_per_cron_run = variable_get('linkchecker_check_links_max', 10);
$check_links_interval = variable_get('linkchecker_check_links_interval', 2419200);
$useragent = variable_get('linkchecker_check_useragent', 'Drupal (+http://drupal.org/)');
// Get URLs for checking.
$result = db_query_range("SELECT * FROM {linkchecker_links} WHERE last_checked < %d AND status = %d ORDER BY last_checked, lid ASC", time() - $check_links_interval, 1, 0, $check_links_max_per_cron_run);
while ($link = db_fetch_object($result)) {
// Fetch URL.
$response = drupal_http_request($link->url, array(
'User-Agent' => 'User-Agent: ' . $useragent,
), $link->method, NULL, 1);
_linkchecker_status_handling($link, $response);
if (timer_read('page') / 1000 > $max_execution_time / 2) {
break;
// Stop once we have used over half of the maximum execution time.
}
}
}