PHP code example of 1gbits / hostdoctor-laravel

1. Go to this page and download the library: Download 1gbits/hostdoctor-laravel library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

1gbits / hostdoctor-laravel example snippets


use OneGbits\HostDoctor\Facades\HostDoctor;

$report = HostDoctor::check('https://example.com');

$report->status;      // "healthy" | "warning" | "degraded" | "critical"
$report->score;       // 0–100
$report->issues;      // Issue[] with stable machine-readable codes
$report->checks;      // normalized per-check data
$report->toArray();   // full schema-shaped array
$report->toJson();    // same as JSON

if ($report->hasIssue('TLS_EXPIRING_SOON')) {
    // alert someone
}

HostDoctor::check('https://api.example.com/health');
HostDoctor::check('example.com');
HostDoctor::check('203.0.113.10');        // network + ports only
HostDoctor::check('203.0.113.10:22');     // e.g. "is SSH up after provisioning?"

HostDoctor::check('https://api.example.com/health', [
    'timeout' => 3.0,
    'expected_status' => [200, 204],
    'ports' => [80, 443, 8080],
    'headers' => ['Authorization' => 'Bearer ...'], // redacted in the report
]);

$http = HostDoctor::http('https://example.com');
// status_code, response_time_ms, protocol ("HTTP/2"), final_url,
// redirects, redirect_chain, redirect_loop, headers, timing
// (dns_ms / tcp_connect_ms / tls_handshake_ms / ttfb_ms / total_ms)

HostDoctor::redirects('http://example.com');
// ['count' => 2, 'loop' => false, 'chain' => [['url' => ..., 'status' => 301], ...]]

$tls = HostDoctor::tls('example.com');          // port 443
$tls = HostDoctor::tls('example.com', 8443);

// enabled, valid, hostname_match, protocol ("TLSv1.3"),
// certificate: subject, issuer, valid_from, valid_until, days_remaining, san
// failure: "expired" | "hostname_mismatch" | "untrusted" | "unreachable" | null

HostDoctor::port('203.0.113.10', 22);
// ['port' => 22, 'status' => 'open', 'latency_ms' => 37, 'error' => null]

HostDoctor::ports('203.0.113.10', [22, 80, 443, 3306]);
// ['22' => [...], '80' => [...], ...]

HostDoctor::network('example.com');
// ['reachable' => true, 'ipv4' => [...], 'ipv6' => [...],
//  'ipv4_available' => true, 'ipv6_available' => true]

HostDoctor::security('https://example.com');
// per-header presence of Strict-Transport-Security, Content-Security-Policy,
// X-Content-Type-Options, X-Frame-Options, Referrer-Policy, Permissions-Policy

// config/hostdoctor.php
'scoring' => [
    'deductions' => ['TLS_EXPIRING_SOON' => 10 /* ... */],
    'status_thresholds' => ['healthy' => 90, 'warning' => 75, 'degraded' => 50],
],

// config/hostdoctor.php
'safe_mode' => false,

// or per instance:
$internal = HostDoctor::withConfig(['safe_mode' => false]);
$internal->port('10.0.0.5', 3306);

$check = HostDoctor::port($server->ip, 22);

if ($check['status'] === 'open') {
    $server->markAsReady();
}

$this->app->instance('hostdoctor', $myFakeHostDoctor);

// or build one with fake probes:
new HostDoctor([], $fakeNetwork, $fakeTcp, $fakeTls, $fakeHttp, $policy);
bash
php artisan vendor:publish --tag=hostdoctor-config
bash
php artisan hostdoctor:check https://example.com
php artisan hostdoctor:check https://api.example.com --expect=200 --timeout=3
php artisan hostdoctor:check https://example.com --json
php artisan hostdoctor:tls example.com --port=443
php artisan hostdoctor:port 203.0.113.10 22 80 443
bash
php artisan hostdoctor:check http://10.0.0.5 --unsafe
bash
php artisan hostdoctor:check https://api.example.com --expect=200 || exit 1
bash
php artisan hostdoctor:check https://customer-site.com --json