Last active
November 27, 2016 07:33
-
-
Save sdennler/1ebb87bdd3a9a03cf1b6a0b8350ae90c to your computer and use it in GitHub Desktop.
Try to do things whit PHP stream_filter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
error_reporting(E_ALL); | |
ini_set('display_errors', 'On'); | |
/** | |
* http://stackoverflow.com/questions/27103269/what-is-a-bucket-brigade | |
* http://stackoverflow.com/questions/38147616/consumed-bytes-for-php-user-filterfilter | |
*/ | |
class append_filter extends php_user_filter { | |
function filter($in, $out, &$consumed, $closing) { | |
echo 'Start New filter whit closing = '.($closing?'TRUE':'FALSE'); | |
$total_read = 0; | |
while ($bucket = stream_bucket_make_writeable($in)) { | |
$total_read += $bucket->datalen; | |
#$bucket->data = str_replace('a', '', $bucket->data); | |
#$bucket->data = str_replace('a', 'ae', $bucket->data); | |
$consumed += $bucket->datalen; # By the example | |
#$consumed += strlen($bucket->data); | |
#$consumed = 0; | |
#$consumed = rand(0, $bucket->datalen*2); | |
#$consumed -= $bucket->datalen; | |
# or just don't change it at all | |
stream_bucket_append($out, $bucket); | |
} | |
echo "; consumed ".(is_null($consumed)?'NULL':$consumed)." of $total_read \n"; | |
return PSFS_PASS_ON; | |
} | |
} | |
stream_filter_register("append", "append_filter"); | |
if(!isset($argv[1]) || !file_exists($argv[1])) die('First argument must be a file.'); | |
$in_file = strpos($argv[1], '.gz') ? 'compress.zlib://'.$argv[1] : $argv[1]; | |
$fin = fopen($in_file, 'rb'); | |
stream_filter_append($fin, 'append', STREAM_FILTER_READ); | |
stream_copy_to_stream($fin, fopen('/tmp/debug.out', 'wb')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment