PHP Function Reference

PHP stream_bucket_prepend() Function



The PHP stream_bucket_prepend() function is used to prepend a bucket to a bucket brigade. It is typically called from php_user_filter::filter() method.

Syntax

stream_bucket_prepend(brigade, bucket)

Parameters

brigade Required. Specify the brigade. brigade is a resource pointing to a bucket brigade which contains one or more bucket objects.
bucket Required. Specify a bucket object.

Return Value

No value is returned.

Example: stream_bucket_prepend() function

The example below shows the usage of stream_bucket_prepend() function.

<?php
class foo extends php_user_filter {
  protected $calls = 0;
  public function filter($in, $out, &$consumed, $closing) {
    while ($bucket = stream_bucket_make_writeable($in)) {
      $consumed += $bucket->datalen;
      if ($this->calls++ == 2) {
        //this bucket will appear again before any other bucket.
        stream_bucket_prepend($in, $bucket);
      }
    }
    return PSFS_FEED_ME;
  }
}

stream_filter_register('test', 'foo');
print file_get_contents('php://filter/read=test/resource=foo');
?>

❮ PHP Streams Reference