@ 2015-12-01T19:33:42Z <?php
class StringStreamWrapper {
const PROTOCOL = "stringstream";
private $stringstream;
private $position;
private $stringlength;
public function stream_open($path, $mode, $options, &$opened_path) {
$contextOptions = stream_context_get_options($this->context);
if (!isset($contextOptions[self::PROTOCOL]['string']))
return false;
$this->position = 0;
// this is our stream!
$this->stringstream = $contextOptions[self::PROTOCOL]['string'];
$this->stringlength = strlen($this->stringstream);
return true;
}
public function stream_read($len) {
$data = substr($this->stringstream, $this->position, $len);
$this->position += strlen($data);
return $data;
}
public function stream_write($data){
$l = strlen($data);
$this->stringstream = substr($this->stringstream, 0, $this->position) . $data . substr($this->stringstream, $this->position += $l);
$this->stringlength = strlen($this->stringstream);
return $l;
}
public function stream_seek($offset, $whence = SEEK_SET) {
if ($whence == SEEK_CUR) {
$this->position += $offset;
}
else if ($whence == SEEK_END) {
$this->position = $this->stringlength + $offset;
}
else {
$this->position = $offset;
}
return true;
}
public function stream_tell() {
return $this->position;
}
public function stream_eof() {
return ($this->position >= $this->stringlength);
}
public function stream_stat() {
return array(
7 => $this->stringlength,
'size' => $this->stringlength,
);
}
static public function Open($string) {
$context = stream_context_create(array(self::PROTOCOL => array('string' => &$string)));
return fopen(self::PROTOCOL . "://",'r', false, $context);
}
}
stream_wrapper_register(StringStreamWrapper::PROTOCOL, "StringStreamWrapper");
#######################################
$testString = 'test';
echo "base64_encode = " . base64_encode($testString).PHP_EOL;
#######################################
# put data in the StringStreamWrapper
$stringstream = StringStreamWrapper::Open($testString);
# get the output stream (as z-push does)
$output = fopen("php://output", "w+");
# attach write filter to output
$filter = stream_filter_append($output, 'convert.base64-encode');
echo "outputstream = ";
# write to output
$bytes = stream_copy_to_stream($stringstream, $output);
write($output, \0);
echo "\n wrote $bytes";
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).
Version System time (s) User time (s) Memory (MiB) 5.6.16 0.010 0.083 20.54 5.6.15 0.003 0.077 18.29 5.6.14 0.007 0.073 18.29 5.6.13 0.013 0.073 18.13 5.6.12 0.007 0.040 21.00 5.6.11 0.000 0.073 21.11 5.6.10 0.007 0.037 21.00 5.6.9 0.010 0.080 21.02 5.6.8 0.003 0.037 20.41 5.5.30 0.003 0.077 17.95 5.5.29 0.010 0.083 17.97 5.5.28 0.003 0.053 20.83 5.5.27 0.013 0.073 20.88 5.5.26 0.003 0.083 20.69 5.5.25 0.007 0.090 20.59 5.5.24 0.020 0.077 20.25
preferences:dark mode live preview
151.46 ms | 1394 KiB | 7 Q