PHP code example of lfischer / internet-available

1. Go to this page and download the library: Download lfischer/internet-available 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/ */

    

lfischer / internet-available example snippets


$available = \lfischer\internet\Internet::available();

use \lfischer\internet\Internet;
use \lfischer\internet\InternetException;
use \lfischer\internet\InternetProblemException;

// Check the availability by connecting to Google on port 80.
$available = (new Internet('www.google.com', 80))->check();

//
try {
    $internet = new Internet(
        'www.google.com', 
        80, 
        Internet::EXCEPTION_ON_UNAVAILABILITY + Internet::PROBLEM_AS_EXCEPTION
    );

    $available = $internet->check();
} catch (InternetException $e) {
    // The internet is not available.
    $internet->getErrorString();
    $internet->getErrorNumber();
    $e->getMessage();
} catch (InternetProblemException $e) {
    // There was a problem while checking the availability.
     $internet->getErrorString();
     $internet->getErrorNumber();
     $e->getMessage();
 }