PHP code example of willwashburn / stream

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

    

willwashburn / stream example snippets


$stream = new \WillWashburn\Stream\Stream();
$stream->write('foo');

$stream->read(3); //foo

$stream->write('bar');
$stream->write('bang');

$stream->read(4); // barb
$stream->peek(3); // ang
$stream->read(3); // ang



$stream = new WillWashburn\Stream\Stream;
 
curl_setopt($ch, CURLOPT_WRITEFUNCTION, function ($ch, $str) use (& $stream, $url) {
            
    $stream->write($str);
    
    try {
        // do something with the stream
        $characters = $stream->read(100);
        
        // tell curl to stop the transfer when we find what we're looking for
        if(strpos($characters,'string im looking for') !==false) {
            return -1;
        }
    }
    catch (StreamBufferTooSmallException $e) {
        // The buffer ended, so keep getting more
        return strlen($str);
    }
    
    //  We return -1 to abort the transfer when we have enough buffered
    return -1;
});