|
|
@ -656,49 +656,35 @@ foreach ($db->getHostPageCrawlQueue(CRAWL_PAGE_LIMIT, time() - CRAWL_PAGE_SECOND |
|
|
|
// Begin snaps |
|
|
|
// Begin snaps |
|
|
|
if (SNAP_STORAGE) { |
|
|
|
if (SNAP_STORAGE) { |
|
|
|
|
|
|
|
|
|
|
|
$crc32data = crc32($content); |
|
|
|
$hostPageSnapTimeAdded = time(); |
|
|
|
|
|
|
|
$hostPageSnapPath = chunk_split($queueHostPage->hostPageId, 1, '/'); |
|
|
|
|
|
|
|
|
|
|
|
$snapTime = time(); |
|
|
|
$hostPageSnapFilenameTmp = __DIR__ . '/../storage/tmp/snap/hp/' . $hostPageSnapPath . $hostPageSnapTimeAdded . '.zip'; |
|
|
|
$snapPath = chunk_split($queueHostPage->hostPageId, 1, '/'); |
|
|
|
@mkdir(__DIR__ . '/../storage/tmp/snap/hp/' . $hostPageSnapPath, 0755, true); |
|
|
|
|
|
|
|
|
|
|
|
$snapTmp = __DIR__ . '/../storage/tmp/snap/hp/' . $snapPath . $snapTime . '.zip'; |
|
|
|
|
|
|
|
@mkdir(__DIR__ . '/../storage/tmp/snap/hp/' . $snapPath, 0755, true); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Create not duplicated data snaps only, even newer by time added |
|
|
|
|
|
|
|
if ($hostPageSnap = $db->findHostPageSnap($queueHostPage->hostPageId, $crc32data)) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$hostPageSnapId = $hostPageSnap->hostPageSnapId; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Create new ZIP container |
|
|
|
// Create new ZIP container |
|
|
|
$zip = new ZipArchive(); |
|
|
|
$zip = new ZipArchive(); |
|
|
|
|
|
|
|
|
|
|
|
if (true === $zip->open($snapTmp, ZipArchive::CREATE)) { |
|
|
|
if (true === $zip->open($hostPageSnapFilenameTmp, ZipArchive::CREATE)) { |
|
|
|
|
|
|
|
|
|
|
|
// Insert compressed snap data into the tmp storage |
|
|
|
// Insert compressed snap data into the tmp storage |
|
|
|
if (true === $zip->addFromString('DATA', $content) && |
|
|
|
if (true === $zip->addFromString('DATA', $content) && |
|
|
|
true === $zip->addFromString('META', sprintf('TIMESTAMP: %s', $snapTime) . PHP_EOL . |
|
|
|
true === $zip->addFromString('META', sprintf('TIMESTAMP: %s', $hostPageSnapTimeAdded) . PHP_EOL . |
|
|
|
sprintf('CRC32: %s', $crc32data . PHP_EOL . |
|
|
|
|
|
|
|
sprintf('MIME: %s', Filter::mime($contentType)) . PHP_EOL . |
|
|
|
sprintf('MIME: %s', Filter::mime($contentType)) . PHP_EOL . |
|
|
|
sprintf('SOURCE: %s', Filter::url(WEBSITE_DOMAIN . '/explore.php?hp=' . $queueHostPage->hostPageId)) . PHP_EOL . |
|
|
|
sprintf('SOURCE: %s', Filter::url(WEBSITE_DOMAIN . '/explore.php?hp=' . $queueHostPage->hostPageId)) . PHP_EOL . |
|
|
|
sprintf('TARGET: %s', Filter::url($queueHostPage->hostPageURL))))) { |
|
|
|
sprintf('TARGET: %s', Filter::url($queueHostPage->hostPageURL)))) { |
|
|
|
|
|
|
|
|
|
|
|
// Done |
|
|
|
// Done |
|
|
|
$zip->close(); |
|
|
|
$zip->close(); |
|
|
|
|
|
|
|
|
|
|
|
// Temporarily snap file exists |
|
|
|
// Temporarily snap file exists |
|
|
|
if (file_exists($snapTmp)) { |
|
|
|
if (file_exists($hostPageSnapFilenameTmp)) { |
|
|
|
|
|
|
|
|
|
|
|
// Register snap in DB |
|
|
|
// Register snap in DB |
|
|
|
if ($hostPageSnapId = $db->addHostPageSnap($queueHostPage->hostPageId, $crc32data, filesize($snapTmp), $snapTime)) { |
|
|
|
if ($hostPageSnapId = $db->addHostPageSnap($queueHostPage->hostPageId, $hostPageSnapTimeAdded)) { |
|
|
|
|
|
|
|
|
|
|
|
$hostPagesSnapAdded++; |
|
|
|
// Default storage success |
|
|
|
} |
|
|
|
$snapFilesExists = false; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Copy files to each storage |
|
|
|
// Copy files to each storage |
|
|
|
foreach (json_decode(SNAP_STORAGE) as $name => $storages) { |
|
|
|
foreach (json_decode(SNAP_STORAGE) as $name => $storages) { |
|
|
@ -712,9 +698,6 @@ foreach ($db->getHostPageCrawlQueue(CRAWL_PAGE_LIMIT, time() - CRAWL_PAGE_SECOND |
|
|
|
|
|
|
|
|
|
|
|
case 'localhost': |
|
|
|
case 'localhost': |
|
|
|
|
|
|
|
|
|
|
|
// Validate size quota |
|
|
|
|
|
|
|
if ($db->getTotalHostPageSnapSizeByStorage($hostPageSnapId, $crc32name) >= $storage->quota->size) continue 2; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Validate mime |
|
|
|
// Validate mime |
|
|
|
if (!$storage->quota->mime) continue 2; |
|
|
|
if (!$storage->quota->mime) continue 2; |
|
|
|
|
|
|
|
|
|
|
@ -731,20 +714,19 @@ foreach ($db->getHostPageCrawlQueue(CRAWL_PAGE_LIMIT, time() - CRAWL_PAGE_SECOND |
|
|
|
if (!$snapMimeValid) continue 2; |
|
|
|
if (!$snapMimeValid) continue 2; |
|
|
|
|
|
|
|
|
|
|
|
// Copy tmp snap file to the permanent storage |
|
|
|
// Copy tmp snap file to the permanent storage |
|
|
|
@mkdir($storage->directory . $snapPath, 0755, true); |
|
|
|
@mkdir($storage->directory . $hostPageSnapPath, 0755, true); |
|
|
|
|
|
|
|
|
|
|
|
if (copy($snapTmp, $storage->directory . $snapPath . $snapTime . '.zip')) { |
|
|
|
if (copy($hostPageSnapFilenameTmp, $storage->directory . $hostPageSnapPath . $hostPageSnapTimeAdded . '.zip')) { |
|
|
|
|
|
|
|
|
|
|
|
// Register storage name |
|
|
|
// Register storage name |
|
|
|
$db->addHostPageSnapStorage($hostPageSnapId, $crc32name, time()); |
|
|
|
$db->addHostPageSnapStorage($hostPageSnapId, $crc32name, time()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$snapFilesExists = true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
break; |
|
|
|
break; |
|
|
|
case 'ftp': |
|
|
|
case 'ftp': |
|
|
|
|
|
|
|
|
|
|
|
// Validate size quota |
|
|
|
|
|
|
|
if ($db->getTotalHostPageSnapSizeByStorage($hostPageSnapId, $crc32name) >= $storage->quota->size) continue 2; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Validate mime |
|
|
|
// Validate mime |
|
|
|
if (!$storage->quota->mime) continue 2; |
|
|
|
if (!$storage->quota->mime) continue 2; |
|
|
|
|
|
|
|
|
|
|
@ -765,12 +747,14 @@ foreach ($db->getHostPageCrawlQueue(CRAWL_PAGE_LIMIT, time() - CRAWL_PAGE_SECOND |
|
|
|
|
|
|
|
|
|
|
|
if ($ftp->connect($storage->host, $storage->port, $storage->username, $storage->password, $storage->directory, $storage->timeout, $storage->passive)) { |
|
|
|
if ($ftp->connect($storage->host, $storage->port, $storage->username, $storage->password, $storage->directory, $storage->timeout, $storage->passive)) { |
|
|
|
|
|
|
|
|
|
|
|
$ftp->mkdir('hp/' . $snapPath, true); |
|
|
|
$ftp->mkdir('hp/' . $hostPageSnapPath, true); |
|
|
|
|
|
|
|
|
|
|
|
if ($ftp->copy($snapTmp, 'hp/' . $snapPath . $snapTime . '.zip')) { |
|
|
|
if ($ftp->copy($hostPageSnapFilenameTmp, 'hp/' . $hostPageSnapPath . $hostPageSnapTimeAdded . '.zip')) { |
|
|
|
|
|
|
|
|
|
|
|
// Register storage name |
|
|
|
// Register storage name |
|
|
|
$db->addHostPageSnapStorage($hostPageSnapId, $crc32name, time()); |
|
|
|
$db->addHostPageSnapStorage($hostPageSnapId, $crc32name, time()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$snapFilesExists = true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$ftp->close(); |
|
|
|
$ftp->close(); |
|
|
@ -781,8 +765,22 @@ foreach ($db->getHostPageCrawlQueue(CRAWL_PAGE_LIMIT, time() - CRAWL_PAGE_SECOND |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// At least one file have been stored |
|
|
|
|
|
|
|
if ($snapFilesExists) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$hostPagesSnapAdded++; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$db->deleteHostPageSnap($hostPageSnapId); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Delete tmp snap |
|
|
|
// Delete tmp snap |
|
|
|
unlink($snapTmp); |
|
|
|
unlink($hostPageSnapFilenameTmp); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Skip page links following with meta robots:nofollow attribute |
|
|
|
// Skip page links following with meta robots:nofollow attribute |
|
|
|