Hi,
I have number of links in my database, which needs to be checked for updates.
Inside each links (first layer), there are numbers of links as well (2nd layer), these links are the actual links that I need to check.
I need to compare a last server update date with the "Last Updated" date that is in each of the 2nd layer links and perform keyword search within them.
The following code is what I've done so far (excluding the search function). What I've got so far is how to get the Last Updated date inside each 2nd layer link so that I can compare it with the latest server update date. However, it's not working, exceeds the processing time.
$query = db_query("select * from links order by state");
$resultCount = db_num_rows($query);
for ($i = 0; $i < resultCount; $i++) {
$result = db_fetch_array($query);
if ($handle = @fopen($result['link'], "r")) {
$content = "";
$base = dirname($result['link']) . '/';
while (!feof($handle)) {
$part = fread($handle, 1024);
$content.= $part;
if (eregi("</body>", $part)) break;
}
fclose($handle);
$urlpattern = '/<a[^>]+href=\"([^\"]+)/i';
preg_match_all($urlpattern, $content, $matches);
$match = array_shift($matches[1]);
foreach ($matches[1] as $u) {
$second_link = $base . $u;
if ($handle2 = @fopen($second_link, "r")) {
$cont = '';
while (!feof($handle2)) {
$par = fread($handle2, 1024*1024);
$pattern = '/' . 'Last Updated:' . '(.*)/';
if (preg_match($pattern, $par, $update)) {
print_r($update[1]);
}
else break;
if (eregi("</body>", $par)) break;
}
}
}
}
}
Any help on this will be appreciated. Thanks!! 🙂