mirror of
https://github.com/alexjustesen/speedtest-tracker.git
synced 2026-06-23 07:40:08 +00:00
@@ -1,50 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\Models\PingAddress;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldBeUnique;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class PingAddressCommand implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(
|
||||
public PingAddress $pingAddress
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
// https://github.com/striebwj/laravel-ping/blob/master/src/LaravelPing.php
|
||||
|
||||
// create a new cURL resource
|
||||
$ch = curl_init($this->pingAddress->url);
|
||||
curl_setopt($ch, CURLOPT_USERAGENT, 'Speedtest Tracker (https://docs.speedtest-tracker.dev)');
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
|
||||
curl_setopt($ch, CURLOPT_MAXREDIRS, 5);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
|
||||
// grab URL and pass it to the browser
|
||||
curl_exec($ch);
|
||||
|
||||
$data = curl_getinfo($ch);
|
||||
|
||||
// close cURL resource, and free up system resources
|
||||
curl_close($ch);
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Ping extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* Indicates if the model should be timestamped.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $timestamps = false;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'http_code',
|
||||
'total_time',
|
||||
'data',
|
||||
'is_successful',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'is_scheduled' => 'boolean',
|
||||
'data' => 'array',
|
||||
'created_at' => 'datetime',
|
||||
];
|
||||
|
||||
public function address()
|
||||
{
|
||||
return $this->belongsTo(PingAddress::class, 'address_id');
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class PingAddress extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'url',
|
||||
'max_redirects',
|
||||
'timeout',
|
||||
];
|
||||
|
||||
public function pings()
|
||||
{
|
||||
return $this->hasMany(Ping::class, 'address_id');
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\PingAddress>
|
||||
*/
|
||||
class PingAddressFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition()
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Ping>
|
||||
*/
|
||||
class PingFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition()
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('ping_addresses', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('url');
|
||||
$table->integer('max_redirects')->default(5);
|
||||
$table->integer('timeout')->default(5);
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('ping_addresses');
|
||||
}
|
||||
};
|
||||
@@ -1,36 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('pings', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('address_id');
|
||||
$table->integer('http_code')->nullable();
|
||||
$table->float('total_time')->nullable();
|
||||
$table->boolean('is_successful')->default(false);
|
||||
$table->json('data')->nullable(); // is a dump of the curl_getinfo() function
|
||||
$table->timestamp('created_at')->useCurrent();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('pings');
|
||||
}
|
||||
};
|
||||
@@ -1,6 +1,5 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
Route::group(
|
||||
@@ -9,27 +8,5 @@ Route::group(
|
||||
],
|
||||
function () {
|
||||
// silence is golden
|
||||
|
||||
Route::get('/', function () {
|
||||
|
||||
// https://github.com/striebwj/laravel-ping/blob/master/src/LaravelPing.php
|
||||
|
||||
// create a new cURL resource
|
||||
$ch = curl_init('https://alexjustesen.com/');
|
||||
curl_setopt($ch, CURLOPT_USERAGENT, 'Speedtest Tracker (https://docs.speedtest-tracker.dev)');
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
|
||||
curl_setopt($ch, CURLOPT_MAXREDIRS, 5);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
|
||||
// grab URL and pass it to the browser
|
||||
curl_exec($ch);
|
||||
|
||||
$data = curl_getinfo($ch);
|
||||
|
||||
// close cURL resource, and free up system resources
|
||||
curl_close($ch);
|
||||
|
||||
dd($data);
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user