PHP code example of varion / driver-stream

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

    

varion / driver-stream example snippets




declare(strict_types=1);

use Varion\Transport\Driver\Stream\StreamDriver;

$driver = new StreamDriver();

$conn = $driver->connect('tcp://127.0.0.1:8080');
$conn->write("hello\n");
echo $conn->read(1024);
$conn->close();



declare(strict_types=1);

use Varion\Transport\Driver\Stream\StreamDriver;

$driver = new StreamDriver();

$listener = $driver->listen('tcp://127.0.0.1:8080');

while ($conn = $listener->accept()) {
    $data = $conn->read(1024);
    $conn->write("HTTP/1.0 200 OK\r\nContent-Length: 2\r\n\r\nOK");
    $conn->close();
}