Skip to content

Commit

Permalink
Ignore connection timeouts while saving links to wayback machine (#472)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kovah committed Jun 10, 2022
1 parent 1e9549e commit a92f3c1
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions app/Helper/WaybackMachine.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@

class WaybackMachine
{
/** @var string */
public static $baseUrl = 'https://web.archive.org';
public static string $baseUrl = 'https://web.archive.org';

/**
* Save an URL to the Wayback Machine
Expand All @@ -25,12 +24,19 @@ public static function saveToArchive(string $url): bool

$archiveUrl = self::$baseUrl . '/save/' . $url;

$request = Http::timeout(10);
$request = Http::timeout(1);
if (config('html-meta.user_agents', false)) {
$agents = config('html-meta.user_agents');
$request->withHeaders(['User-Agent' => $agents[array_rand($agents)]]);
}
$response = $request->head($archiveUrl);
try {
$response = $request->head($archiveUrl);
} catch (\Exception $e) {
if (!str_contains($e->getMessage(), 'cURL error 28: Operation timed out')) {
Log::warning($archiveUrl . ': ' . $e->getMessage());
}
return false;
}

try {
$response->throw();
Expand Down

0 comments on commit a92f3c1

Please sign in to comment.