PHP code example of anvilm / php.transport

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

    

anvilm / php.transport example snippets


use AnvilM\Transport\Client

$client = Client::tcp('example.com:80');

use AnvilM\Transport\Client

$client = Client::upd('example.com:80');

use AnvilM\Transport\Client

$client = Client::tls('example.com:80');

use AnvilM\Transport\Client

$client = Client::tcp('example.com:80');

$timeout = 3; // Timeout in seconds

$client->open($timeout);

use AnvilM\Transport\Client

$client = Client::tcp('example.com:80');

$data = 'hello'; // Data to send
$timeout = 30; // Write timeout
$length = strlen($data); // Length of data to send

// Open connection and send packet
$client->open()->write(pack('V', $data), $length);

use AnvilM\Transport\Client

$client = Client::tcp('example.com:80');

$length = 1024; // Length of data for read
$timeout = 30; // Timeout to wait for data from server

// Open connection and read data
$data = $client->open()->read($length, $timeout);

use AnvilM\Transport\Client

$client = Client::tcp('example.com:80')->open()
    ->close()
    ->open();

use AnvilM\Transport\Client
use AnvilM\Transport\Connection\Context\TLSContext;

$context = (new TLSContext())->timeout(5.5)
    ->verifyPeer(true)
    ->verifyPeerName(true);
        
$client = Client::tls('example.com:443', $context);

$client->open(); // Open with timeout 5.5

$context->timeout(10); // Set new timeout

$data = $client->read(); // Read data with new timeout

use AnvilM\Transport\Client
use AnvilM\Transport\Connection\Socket\Socket;

$client = Client::tcp('example.com:443');

$socket = $client->getSocket();

$socket->open()->enableCrypto();
bash
composer