mirror of
https://github.com/alexjustesen/speedtest-tracker.git
synced 2026-06-23 07:20:09 +00:00
b21f0f18d7
Co-authored-by: Alex Justesen <1144087+alexjustesen@users.noreply.github.com>
34 lines
742 B
PHP
34 lines
742 B
PHP
<?php
|
|
|
|
namespace App\Actions;
|
|
|
|
use Illuminate\Support\Facades\Log;
|
|
use Lorisleiva\Actions\Concerns\AsAction;
|
|
use Spatie\Ping\Ping;
|
|
use Spatie\Ping\PingResult;
|
|
|
|
class PingHostname
|
|
{
|
|
use AsAction;
|
|
|
|
public function handle(?string $hostname = null, int $count = 1): PingResult
|
|
{
|
|
$hostname = $hostname ?? config('speedtest.preflight.internet_check_hostname');
|
|
|
|
// Remove protocol if present
|
|
$hostname = preg_replace('#^https?://#', '', $hostname);
|
|
|
|
$ping = (new Ping(
|
|
hostname: $hostname,
|
|
count: $count,
|
|
))->run();
|
|
|
|
Log::info('Pinged hostname', [
|
|
'host' => $hostname,
|
|
'data' => $ping->toArray(),
|
|
]);
|
|
|
|
return $ping;
|
|
}
|
|
}
|