File tree Expand file tree Collapse file tree 2 files changed +32
-21
lines changed
Expand file tree Collapse file tree 2 files changed +32
-21
lines changed Original file line number Diff line number Diff line change @@ -42,26 +42,7 @@ public function __construct(
4242 */
4343 public function handle (): void
4444 {
45- /**
46- * Check for an internet connection first.
47- */
48- $ ping = new Ping (
49- host: config ('speedtest.ping_url ' ),
50- timeout: 3 ,
51- );
52-
53- if ($ ping ->ping () === false ) {
54- $ this ->result ->update ([
55- 'data ' => [
56- 'type ' => 'log ' ,
57- 'level ' => 'error ' ,
58- 'message ' => 'Could not resolve host. ' ,
59- ],
60- 'status ' => ResultStatus::Failed,
61- ]);
62-
63- SpeedtestFailed::dispatch ($ this ->result );
64-
45+ if (! $ this ->checkForInternetConnection ()) {
6546 return ;
6647 }
6748
@@ -104,4 +85,34 @@ public function handle(): void
10485
10586 SpeedtestCompleted::dispatch ($ this ->result );
10687 }
88+
89+ protected function checkForInternetConnection (): bool
90+ {
91+ // Skip checking for internet connection if ping url isn't set (disabled)
92+ if (blank (config ('speedtest.ping_url ' ))) {
93+ return true ;
94+ }
95+
96+ $ ping = new Ping (
97+ host: config ('speedtest.ping_url ' ),
98+ timeout: 3 ,
99+ );
100+
101+ if ($ ping ->ping () === false ) {
102+ $ this ->result ->update ([
103+ 'data ' => [
104+ 'type ' => 'log ' ,
105+ 'level ' => 'error ' ,
106+ 'message ' => 'Could not resolve host. ' ,
107+ ],
108+ 'status ' => ResultStatus::Failed,
109+ ]);
110+
111+ SpeedtestFailed::dispatch ($ this ->result );
112+
113+ return false ;
114+ }
115+
116+ return true ;
117+ }
107118}
Original file line number Diff line number Diff line change 2929 /**
3030 * Speedtest settings.
3131 */
32- 'ping_url ' => env ('SPEEDTEST_PING_URL ' , ' 1.1.1.1 ' ),
32+ 'ping_url ' => env ('SPEEDTEST_PING_URL ' ),
3333
3434 'schedule ' => env ('SPEEDTEST_SCHEDULE ' ),
3535
You can’t perform that action at this time.
0 commit comments