|
|
|
@ -18,11 +18,14 @@ $aContext = array(
@@ -18,11 +18,14 @@ $aContext = array(
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$STH = $pdo->query ("SELECT `name`, `url`, `etag` FROM `subscriptions` WHERE `active` = 1"); |
|
|
|
|
$STH = $pdo->query ("SELECT `name`, `url`, `modified`, `etag` FROM `subscriptions` WHERE `active` = 1"); |
|
|
|
|
$lists = $STH->fetchAll(PDO::FETCH_ASSOC); |
|
|
|
|
|
|
|
|
|
foreach ($lists as $list) { |
|
|
|
|
echo "Processing " . $list['name'] . " subscription..." . PHP_EOL; |
|
|
|
|
echo "Processing " . $list['name'] . " subscription..."; |
|
|
|
|
|
|
|
|
|
if (!empty($list['modified'])) |
|
|
|
|
$aContext['http']['header'] = 'If-Modified-Since: ' . $list['modified'] . '\r\n'; |
|
|
|
|
|
|
|
|
|
if (!empty($list['etag'])) |
|
|
|
|
$aContext['http']['header'] = 'If-None-Match: ' . $list['etag'] . '\r\n'; |
|
|
|
@ -34,19 +37,20 @@ foreach ($lists as $list) {
@@ -34,19 +37,20 @@ foreach ($lists as $list) {
|
|
|
|
|
$f_meta = stream_get_meta_data($f); |
|
|
|
|
|
|
|
|
|
if (strpos($f_meta['wrapper_data'][0], "200") === false) { |
|
|
|
|
echo " no changes." . PHP_EOL; |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$etagHeader = array_filter($f_meta['wrapper_data'], function($el) { |
|
|
|
|
return (strpos($el, "ETag") !== false); |
|
|
|
|
}); |
|
|
|
|
$lastmod = $util->getResponseHeader("Last-Modified", $f_meta['wrapper_data']); |
|
|
|
|
$etag = $util->getResponseHeader("Etag", $f_meta['wrapper_data']); |
|
|
|
|
|
|
|
|
|
if ($etagHeader) { |
|
|
|
|
$etag = substr($etagHeader[array_keys($etagHeader)[0]], 6); |
|
|
|
|
var_dump($etag); |
|
|
|
|
$pdo->exec("UPDATE `subscriptions` SET `etag` = '" . $etag . "' WHERE `name` = '" . $list['name'] . "'"); |
|
|
|
|
if (!empty($lastmod) || !empty($etag)) { |
|
|
|
|
$pdo->exec("UPDATE `subscriptions` SET " . (!empty($lastmod) ? ("`modified` = '" . $lastmod . "' ") : "") . (!empty($etag) ? ("`etag` = '" . $etag . "' ") : "") . "WHERE `name` = '" . $list['name'] . "'"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// reset line |
|
|
|
|
echo " fetching updated list." . PHP_EOL; |
|
|
|
|
|
|
|
|
|
while (($buffer = fgets($f, 4096)) !== false) { |
|
|
|
|
$domain = ""; |
|
|
|
|
$record = $util->parseHostRecord($buffer); |
|
|
|
|