forked from alexjustesen/speedtest-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPingHostname.php
More file actions
36 lines (27 loc) · 819 Bytes
/
PingHostname.php
File metadata and controls
36 lines (27 loc) · 819 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?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();
$data = $ping->toArray();
unset($data['raw_output'], $data['lines']);
Log::debug('Pinged hostname', [
'host' => $hostname,
'data' => $data,
]);
return $ping;
}
}