PHP code example of phizzl / networktools

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

    

phizzl / networktools example snippets


use Phizzl\NetworkTools\Http\HttpHeader;
use Phizzl\NetworkTools\Http\HttpRequest;

$header = new HttpHeader();
$header->set('X-Awesome', 'Foo');
$http = new HttpRequest();
$http->setHost("https://www.google.com");
$http->setHeader($header);
$response = $http->send();
$contents = $response->getBody()->getContents();

echo "www.google.com responded with status code {$response->getStatusCode()}\n";

use Phizzl\NetworkTools\Ping\Ping;

$ping = new Ping("127.0.0.1");
$latency = $ping->ping();

echo "Latency {$latency}s for 127.0.0.1\n";

use Phizzl\NetworkTools\Tcp\Tcp;

$port = 22;
$tcp = new Tcp();
$tcp->setHost("github.com");
$tcp->setPort($port);

if($tcp->send()){
    echo "Githubs port $port is open\n";
}
else{
    echo "Githubs port $port is closed\n";
}