PHP code example of matasarei / phptcp

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

    

matasarei / phptcp example snippets


use Matasar\PhpTcp\Client;
use Matasar\PhpTcp\Request;
use Matasar\PhpTcp\Socket\StreamSocket;

$client = new Client('ip_or_hostname', 8888, new StreamSocket());
$client->connect();

$request = new Request('request');
$response = $client->request($request);
$client->disconnect();

var_dump($response->getData());

use Matasar\PhpTcp\Socket\FSocket;

new FSocket(0); // disable blocking.

use Matasar\PhpTcp\Client;
use Matasar\PhpTcp\Socket\FSocket;

$client = new Client('hostname', 1234, new FSocket());

$client->setChunkSize(8192); // read data by 8 Kb per cycle.
$client->setConnectionLag(5000); // 5 ms pause per cycle.
$client->setLogger(new SomePsrLogger()); // connect a logger for debugging.