Skip to content

Instantly share code, notes, and snippets.

@cythrawll
Created February 3, 2014 17:47
Show Gist options
  • Save cythrawll/8788694 to your computer and use it in GitHub Desktop.
Save cythrawll/8788694 to your computer and use it in GitHub Desktop.
<?php
class StreamThingy {
public $fh; //this si your fopen statement
public $readFunc;
public function onRead($function) {
$this->readFunc = $function;
}
public function execute() {
$this->fh = //do fopen logic
$bytes = 4096;
while($str = call_user_func(array($this, 'readFunc'), $fh, $bytes) !== FALSE) {
//do something here
}
}
}
$streamObj = new StreamThingy();
$streamObj->onRead(function($handle, $bytes) { return fread($fh, $bytes); });
$streamObj->execute();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment