PHP code example of krinfreschi / async-streams

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

    

krinfreschi / async-streams example snippets


async_stream_register_read(resource $handle, callable $callable) //$callable will receive args: $handle
async_stream_remove_read(resource $handle)
async_stream_register_write(resource $handle, callable $callable) //$callable will receive args: $handle, $written, $unwritten
async_stream_remove_write(resource $handle)

use krinfreschi\AsyncStreams\AsyncStreamWrapper;

 AsyncStreamWrapper::make($resource);
fwrite($handle, 'data');

async_stream_register_write($handle, function($handle, $written, $unwritten) {
    fseek($handle, 0);
    var_dump(stream_get_contents($handle));
    fclose($handle);
});

AsyncStreamWrapper::run();