<?php
class F extends php_user_filter
{
public function onCreate()
{
echo 'filter onCreate' . PHP_EOL;
return true;
}
public function onClose()
{
echo 'filter onClose' . PHP_EOL;
}
public function filter($in, $out, &$consumed, $closing)
{
while ($bucket = stream_bucket_make_writeable($in)) {
$bucket->data = strtoupper($bucket->data);
$consumed += $bucket->datalen;
stream_bucket_append($out, $bucket);
}
echo 'filtered ' . ($consumed ? $consumed : 0) . ' bytes';
if ($closing) {
echo ' and closing.';
} else {
echo '.';
}
if (feof($this->stream)) {
echo ' Stream has reached end-of-file.';
}
echo PHP_EOL;
return PSFS_PASS_ON;
}
}
stream_filter_register('f', 'F');
$str = str_repeat('a', 8320);
echo 'tmpfile()' . PHP_EOL;
$f1 = tmpfile();
fwrite($f1, $str);
fseek($f1, 0, SEEK_SET);
stream_filter_append($f1, 'f', STREAM_FILTER_READ);
echo stream_get_contents($f1) . PHP_EOL;
fclose($f1);
echo PHP_EOL . PHP_EOL;
echo 'php://temp' . PHP_EOL;
$f2 = fopen('php://temp', 'r+b');
fwrite($f2, $str);
fseek($f2, 0, SEEK_SET);
stream_filter_append($f2, 'f', STREAM_FILTER_READ);
echo stream_get_contents($f2) . PHP_EOL;
fclose($f2);
echo PHP_EOL . PHP_EOL;
echo 'php://memory' . PHP_EOL;
$f3 = fopen('php://memory', 'r+b');
fwrite($f3, $str);
fseek($f3, 0, SEEK_SET);
stream_filter_append($f3, 'f', STREAM_FILTER_READ);
echo stream_get_contents($f3) . PHP_EOL;
fclose($f3);
echo PHP_EOL;
preferences:
43.08 ms | 402 KiB | 5 Q