Skip to content

Commit

Permalink
[Feature] Use ping instead of a HTTP get request to check for interne…
Browse files Browse the repository at this point in the history
…t connection (#1493)
  • Loading branch information
alexjustesen authored Jun 8, 2024
1 parent ac0556f commit 24efee2
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 7 deletions.
13 changes: 8 additions & 5 deletions app/Jobs/Speedtests/ExecuteOoklaSpeedtest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Http;
use JJG\Ping;
use Symfony\Component\Process\Exception\ProcessFailedException;
use Symfony\Component\Process\Process;

Expand Down Expand Up @@ -43,11 +43,14 @@ public function __construct(
public function handle(): void
{
/**
* Check to make sure there is an internet connection first.
* Check for an internet connection first.
*/
try {
Http::retry(3, 500)->get('1.1.1.1');
} catch (\Throwable $th) {
$ping = new Ping(
host: config('speedtest.ping_url'),
timeout: 3,
);

if ($ping->ping() === false) {
$this->result->update([
'data' => [
'type' => 'log',
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"dragonmantank/cron-expression": "^3.3.3",
"filament/filament": "^3.2.86",
"filament/spatie-laravel-settings-plugin": "^3.2.86",
"geerlingguy/ping": "^1.2.1",
"guzzlehttp/guzzle": "^7.8.1",
"influxdata/influxdb-client-php": "^3.5",
"laravel-notification-channels/telegram": "^5.0",
Expand Down
39 changes: 38 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions config/speedtest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
/**
* Speedtest settings.
*/
'ping_url' => env('SPEEDTEST_PING_URL', '1.1.1.1'),

'schedule' => env('SPEEDTEST_SCHEDULE'),

'servers' => env('SPEEDTEST_SERVERS', ''),
Expand Down
2 changes: 1 addition & 1 deletion docker/8.3/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

RUN apt-get update \
&& mkdir -p /etc/apt/keyrings \
&& 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 \
&& 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 \
&& curl -sS 'https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x14aa40ec0831756756d7f66c4f4ea0aae5267a6c' | gpg --dearmor | tee /etc/apt/keyrings/ppa_ondrej_php.gpg > /dev/null \
&& 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 \
&& apt-get update \
Expand Down

0 comments on commit 24efee2

Please sign in to comment.