Skip to content

Commit 24efee2

Browse files
authored
[Feature] Use ping instead of a HTTP get request to check for internet connection (alexjustesen#1493)
1 parent ac0556f commit 24efee2

File tree

5 files changed

+50
-7
lines changed

5 files changed

+50
-7
lines changed

app/Jobs/Speedtests/ExecuteOoklaSpeedtest.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
use Illuminate\Queue\InteractsWithQueue;
1414
use Illuminate\Queue\SerializesModels;
1515
use Illuminate\Support\Arr;
16-
use Illuminate\Support\Facades\Http;
16+
use JJG\Ping;
1717
use Symfony\Component\Process\Exception\ProcessFailedException;
1818
use Symfony\Component\Process\Process;
1919

@@ -43,11 +43,14 @@ public function __construct(
4343
public function handle(): void
4444
{
4545
/**
46-
* Check to make sure there is an internet connection first.
46+
* Check for an internet connection first.
4747
*/
48-
try {
49-
Http::retry(3, 500)->get('1.1.1.1');
50-
} catch (\Throwable $th) {
48+
$ping = new Ping(
49+
host: config('speedtest.ping_url'),
50+
timeout: 3,
51+
);
52+
53+
if ($ping->ping() === false) {
5154
$this->result->update([
5255
'data' => [
5356
'type' => 'log',

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"dragonmantank/cron-expression": "^3.3.3",
1515
"filament/filament": "^3.2.86",
1616
"filament/spatie-laravel-settings-plugin": "^3.2.86",
17+
"geerlingguy/ping": "^1.2.1",
1718
"guzzlehttp/guzzle": "^7.8.1",
1819
"influxdata/influxdb-client-php": "^3.5",
1920
"laravel-notification-channels/telegram": "^5.0",

composer.lock

Lines changed: 38 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/speedtest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
/**
3030
* Speedtest settings.
3131
*/
32+
'ping_url' => env('SPEEDTEST_PING_URL', '1.1.1.1'),
33+
3234
'schedule' => env('SPEEDTEST_SCHEDULE'),
3335

3436
'servers' => env('SPEEDTEST_SERVERS', ''),

docker/8.3/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
1717

1818
RUN apt-get update \
1919
&& mkdir -p /etc/apt/keyrings \
20-
&& apt-get install -y gnupg gosu curl ca-certificates zip unzip git supervisor sqlite3 libcap2-bin libpng-dev python2 dnsutils librsvg2-bin fswatch nano cron \
20+
&& apt-get install -y gnupg gosu curl ca-certificates zip unzip git supervisor sqlite3 libcap2-bin libpng-dev python2 dnsutils iputils-ping librsvg2-bin fswatch nano cron \
2121
&& curl -sS 'https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x14aa40ec0831756756d7f66c4f4ea0aae5267a6c' | gpg --dearmor | tee /etc/apt/keyrings/ppa_ondrej_php.gpg > /dev/null \
2222
&& echo "deb [signed-by=/etc/apt/keyrings/ppa_ondrej_php.gpg] https://ppa.launchpadcontent.net/ondrej/php/ubuntu jammy main" > /etc/apt/sources.list.d/ppa_ondrej_php.list \
2323
&& apt-get update \

0 commit comments

Comments
 (0)